Suggestions
in package
Autocomplete answers for command options — card names, sets, booster types, set types, keywords and formats — fast enough to run on every keystroke inside Discord's three-second window.
Card names, sets and keywords are read from the build once into memory (a few megabytes) and read again when a new build is installed. Nothing is suggested while the build is not open yet.
Tags
Table of Contents
Constants
- LIMIT : int = 25
- Discord's limit on autocomplete choices.
Properties
- $database : Database
- $keywords : array<string|int, string>
- Distinct keywords, sorted.
- $names : array<string, string>
- Distinct card names, lower case → name.
- $sets : array<string, array{name: string, releaseDate: ?string, type: ?string, boosters: bool}>
- Sets, newest first: code → {name, releaseDate, type, boosters}.
- $version : string|null
- The build version the lists were read from.
Methods
- __construct() : mixed
- cardNames() : array<string|int, string>
- Card names matching what was typed: names starting with it first, then names with a word starting with it, then any containing it; shorter names first within each.
- formats() : array<string, string>
- The formats MTGJSON tracks legality in, matching what was typed.
- keywords() : array<string|int, string>
- Keywords (keyword abilities, actions and ability words found on cards) matching what was typed, prefix matches first.
- printingSets() : array<string, string>
- The sets a card was printed in, newest first.
- set() : array{name: string, releaseDate: ?string, type: ?string, boosters: bool}|null
- A set's name and release date, if the build has it.
- sets() : array<string, string>
- Sets matching what was typed, by code or name, newest first. A code typed exactly comes first.
- setTypes() : array<string|int, string>
- The set types (`expansion`, `core`, `masters`, …) matching what was typed.
- load() : bool
- Reads the lists, once per build.
- setLabel() : string
Constants
LIMIT
Discord's limit on autocomplete choices.
public
int
LIMIT
= 25
Properties
$database
protected
Database
$database
$keywords
Distinct keywords, sorted.
protected
array<string|int, string>
$keywords
= []
$names
Distinct card names, lower case → name.
protected
array<string, string>
$names
= []
$sets
Sets, newest first: code → {name, releaseDate, type, boosters}.
protected
array<string, array{name: string, releaseDate: ?string, type: ?string, boosters: bool}>
$sets
= []
$version
The build version the lists were read from.
protected
string|null
$version
= null
Methods
__construct()
public
__construct(Database $database) : mixed
Parameters
- $database : Database
-
The card build.
cardNames()
Card names matching what was typed: names starting with it first, then names with a word starting with it, then any containing it; shorter names first within each.
public
cardNames(string $typed[, int $limit = self::LIMIT ]) : array<string|int, string>
Parameters
- $typed : string
- $limit : int = self::LIMIT
Return values
array<string|int, string>formats()
The formats MTGJSON tracks legality in, matching what was typed.
public
formats([string $typed = '' ]) : array<string, string>
Parameters
- $typed : string = ''
Return values
array<string, string> —Key → friendly name.
keywords()
Keywords (keyword abilities, actions and ability words found on cards) matching what was typed, prefix matches first.
public
keywords([string $typed = '' ]) : array<string|int, string>
Parameters
- $typed : string = ''
Return values
array<string|int, string>printingSets()
The sets a card was printed in, newest first.
public
printingSets(string $name[, string $typed = '' ]) : array<string, string>
Parameters
- $name : string
-
The card's exact name.
- $typed : string = ''
-
Filters the sets by code or name.
Return values
array<string, string> —Code → label.
set()
A set's name and release date, if the build has it.
public
set(string $code) : array{name: string, releaseDate: ?string, type: ?string, boosters: bool}|null
Parameters
- $code : string
Return values
array{name: string, releaseDate: ?string, type: ?string, boosters: bool}|nullsets()
Sets matching what was typed, by code or name, newest first. A code typed exactly comes first.
public
sets(string $typed[, bool $boosters = false ][, int $limit = self::LIMIT ]) : array<string, string>
Parameters
- $typed : string
- $boosters : bool = false
-
Only sets MTGJSON has booster configurations for.
- $limit : int = self::LIMIT
Return values
array<string, string> —Code → label (Name (CODE, year)).
setTypes()
The set types (`expansion`, `core`, `masters`, …) matching what was typed.
public
setTypes([string $typed = '' ]) : array<string|int, string>
Parameters
- $typed : string = ''
Return values
array<string|int, string>load()
Reads the lists, once per build.
protected
load() : bool
Return values
bool —Whether the build is open.
setLabel()
protected
setLabel(string $code, array<string|int, mixed> $set) : string
Parameters
- $code : string
- $set : array<string|int, mixed>