Help
in package
implements
Module
uses
InteractionTrait
`/help` โ a guide to every command, as one Components V2 message, only to the person who asked. The guide is {@see SECTIONS}, so it is tested and kept beside the commands it describes.
Tags
Table of Contents
Interfaces
- Module
- A self-contained bot feature, as in Tutelar: it declares its own application commands ({@see commands()}, which the client registers or updates), listens for them, and routes clicks on the components of the messages it sends, from {@see boot()}.
Constants
-
SECTIONS
: array<int, array{title: string, lines: list
}> = [['title' => 'Cards', 'lines' => ['`/card show... - The guide, in order: a title and its lines.
Methods
- boot() : void
- Registers commands and listeners. Called once, after the gateway and the application are ready.
- commands() : array<string|int, CommandBuilder>
- The application commands the module answers, as they should be registered. The client creates missing ones and updates changed ones.
- guide() : MessageBuilder
- The guide as a message.
- name() : string
- Stable short name, for logs.
- answer() : PromiseInterface
- Answers a component click with a new message, or by replacing the clicked message, logging what fails.
- choices() : array<string|int, array{name: string, value: string}>
- Autocomplete choices from `value => label` (or a list of values).
- command() : CommandBuilder
- A chat command usable in servers, the bot's DMs and group DMs, from a server install or a user install.
- failure() : MessageBuilder
- The message for a failure.
- hidden() : Option
- The `hidden` option every command takes: reply only to the caller.
- option() : Option
- A command option.
- reply() : PromiseInterface
- Defers the reply, then answers with what `$work` resolves to. A failure answers too: a bad search is the caller's to fix, anything else is logged.
- subcommand() : Option
- A sub-command with its options.
- typed() : array<string, mixed>
- The values typed so far into the command being autocompleted, from inside its sub-command.
- values() : array<string, mixed>
- Option values by name.
- show() : PromiseInterface
- `/help`.
Constants
SECTIONS
The guide, in order: a title and its lines.
public
array<int, array{title: string, lines: list}>
SECTIONS
= [['title' => 'Cards', 'lines' => ['`/card show <name> [set]` โ a card: its art, rules text, today\'s price and its set. Buttons open its **rulings**, **legality**, **prices**, **foreign names**, full **image** and raw **JSON**; **Flip** turns a double-faced card; a picker switches to another printing; links go to Scryfall, EDHREC and stores.', '`/card search` โ cards by any mix of name, type, rules text, colors, color identity (`UR`, `W,U,B`), mana value (`3`, `>=5`), rarity, set, format legality, keyword, artist, power and toughness. Pages of results; pick one to open it.', '`/card random [filters]` โ a random card, with ๐ฒ **Another**.', '`/card prices <name> [set]` โ today\'s prices from TCGplayer, Card Kingdom, Cardmarket, Mana Pool and Cardhoarder, retail and buylist.', '`/card_search` โ the original search, still here.']], ['title' => 'Sets, boosters and decks', 'lines' => ['`/set show <set>` ยท `/set search [name] [type] [block] [year]` โ a set\'s size, dates and boosters, with buttons to browse its cards, open a booster and list its decks.', '`/booster <set> [type]` โ open a pack, with the real product\'s odds: play, draft, collector and more. **Open another**, **Images**, and the pack\'s value.', '`/deck show <deck>` ยท `/deck search [name] [set] [type]` โ preconstructed decks with their cards, and **Export decklist** for MTG Arena or Moxfield.']], ['title' => 'In chat', 'lines' => ['Right-click a message โ Apps โ **Find cards** โ looks up every `[[Card Name]]` in it (or `[[Card Name|SET]]`), or the whole message as one name.', 'If the bot is set up to read messages, it also answers `[[Card Name]]` wherever you write it.']], ['title' => 'Everything else', 'lines' => ['`/help` โ this guide. `/about` โ where the data comes from and how fresh it is. `/invite` โ add the bot to a server or to your account. `/ping` โ gateway latency.', 'Every command takes `hidden:true` to answer only you. Names, sets, keywords and formats autocomplete as you type.']]]
Methods
boot()
Registers commands and listeners. Called once, after the gateway and the application are ready.
public
boot(MTG $mtg) : void
Parameters
- $mtg : MTG
Tags
commands()
The application commands the module answers, as they should be registered. The client creates missing ones and updates changed ones.
public
commands(MTG $mtg) : array<string|int, CommandBuilder>
Parameters
- $mtg : MTG
Tags
Return values
array<string|int, CommandBuilder>guide()
The guide as a message.
public
static guide() : MessageBuilder
Return values
MessageBuildername()
Stable short name, for logs.
public
name() : string
Tags
Return values
stringanswer()
Answers a component click with a new message, or by replacing the clicked message, logging what fails.
protected
static answer(MTG $mtg, Interaction $interaction, callable $work[, bool $update = false ]) : PromiseInterface
Parameters
- $mtg : MTG
- $interaction : Interaction
- $work : callable
-
Returns a MessageBuilder or a promise of one.
- $update : bool = false
-
Replace the clicked message instead of answering with a new, hidden one.
Return values
PromiseInterfacechoices()
Autocomplete choices from `value => label` (or a list of values).
protected
static choices(array<string|int, mixed> $choices) : array<string|int, array{name: string, value: string}>
Parameters
- $choices : array<string|int, mixed>
Return values
array<string|int, array{name: string, value: string}>command()
A chat command usable in servers, the bot's DMs and group DMs, from a server install or a user install.
protected
static command(string $name, string $description) : CommandBuilder
Parameters
- $name : string
- $description : string
Return values
CommandBuilderfailure()
The message for a failure.
protected
static failure(MTG $mtg, Throwable $e) : MessageBuilder
Parameters
- $mtg : MTG
- $e : Throwable
Return values
MessageBuilderhidden()
The `hidden` option every command takes: reply only to the caller.
protected
static hidden(MTG $mtg) : Option
Parameters
- $mtg : MTG
Return values
Optionoption()
A command option.
protected
static option(MTG $mtg, int $type, string $name, string $description[, bool $required = false ][, bool $autocomplete = false ]) : Option
Parameters
- $mtg : MTG
- $type : int
-
An Option type constant.
- $name : string
- $description : string
- $required : bool = false
- $autocomplete : bool = false
Return values
Optionreply()
Defers the reply, then answers with what `$work` resolves to. A failure answers too: a bad search is the caller's to fix, anything else is logged.
protected
static reply(MTG $mtg, Interaction $interaction, bool $hidden, callable $work) : PromiseInterface
Parameters
- $mtg : MTG
- $interaction : Interaction
- $hidden : bool
-
Whether only the caller sees the answer.
- $work : callable
-
Returns a MessageBuilder or a promise of one.
Return values
PromiseInterfacesubcommand()
A sub-command with its options.
protected
static subcommand(MTG $mtg, string $name, string $description, Option ...$options) : Option
Parameters
- $mtg : MTG
- $name : string
- $description : string
- $options : Option
Return values
Optiontyped()
The values typed so far into the command being autocompleted, from inside its sub-command.
protected
static typed(Interaction $interaction) : array<string, mixed>
Parameters
- $interaction : Interaction
Return values
array<string, mixed>values()
Option values by name.
protected
static values(iterable<string|int, mixed> $options) : array<string, mixed>
Parameters
- $options : iterable<string|int, mixed>
-
The options a command handler is given.
Return values
array<string, mixed>show()
`/help`.
private
show(Interaction $interaction) : PromiseInterface
Parameters
- $interaction : Interaction