ActionRegistry
in package
The catalogue of every action the bot knows, and the single place every adapter looks when it wires itself up.
Actions are keyed by qualifier and leaf name — twitch title — which is the
shortest form any surface uses, so a collision here is a collision
everywhere. It throws rather than overwriting: two actions answering to
!twitch title would otherwise mean whichever registered last wins, with
nothing in the log to say so, and the loser's package would look broken from
the outside.
That check is the whole reason qualifiers exist. It cannot fire between two connectors, because each owns its own qualifier and addFrom() refuses anything else — which means a connector can be installed without auditing what every other connector happens to call things.
Tags
Table of Contents
Properties
Methods
- add() : self
- addAll() : self
- Adds every action from a provider, without the qualifier check.
- addFrom() : self
- Adds every action a connector brings, holding it to its own qualifier.
- all() : array<string, Action>
- count() : int
- forQualifier() : array<string, Action>
- Everything one connector brought.
- forSurface() : array<string, Action>
- Everything offered on one surface.
- get() : Action|null
- grouped() : array<string, array<int, Action>>
- Actions grouped for a help listing, in registration order within each group, and filtered to what `$access` may actually run — somebody asking for help should not be shown a list of things they will be refused.
- has() : bool
- Whether anything answers to this qualified name or alias.
- qualifiers() : array<int, string>
- Every qualifier that has at least one action, in the order they were first seen — which is the order a connector was added.
-
resolve()
: Action, 1: list
} - Resolves however a chat spelled a command, in either of the two forms a surface may use.
- normalise() : string
- Collapses whitespace so `twitch title` and `twitch title` are one key.
Properties
$actions
private
array<string, Action>
$actions
= []
keyed by Action::key()
$aliases
private
array<string, string>
$aliases
= []
qualified alias => action key
Methods
add()
public
add(Action $action) : self
Parameters
- $action : Action
Return values
selfaddAll()
Adds every action from a provider, without the qualifier check.
public
addAll(ProvidesActions $provider) : self
Parameters
- $provider : ProvidesActions
Return values
selfaddFrom()
Adds every action a connector brings, holding it to its own qualifier.
public
addFrom(ProvidesActions $provider, string $qualifier) : self
A connector that claimed another's qualifier could shadow its commands from a separate package, which is exactly what none of this should be able to do.
Parameters
- $provider : ProvidesActions
- $qualifier : string
Return values
selfall()
public
all() : array<string, Action>
Return values
array<string, Action>count()
public
count() : int
Return values
intforQualifier()
Everything one connector brought.
public
forQualifier(string $qualifier) : array<string, Action>
Parameters
- $qualifier : string
Return values
array<string, Action>forSurface()
Everything offered on one surface.
public
forSurface(Surface $surface) : array<string, Action>
Parameters
- $surface : Surface
Return values
array<string, Action>get()
public
get(string $key) : Action|null
Parameters
- $key : string
Return values
Action|nullgrouped()
Actions grouped for a help listing, in registration order within each group, and filtered to what `$access` may actually run — somebody asking for help should not be shown a list of things they will be refused.
public
grouped(Surface $surface, Access $access) : array<string, array<int, Action>>
Grouped by qualifier and then group, because with several connectors installed "which platform is this for" is the first thing a reader needs.
Parameters
Return values
array<string, array<int, Action>>has()
Whether anything answers to this qualified name or alias.
public
has(string $key) : bool
Parameters
- $key : string
Return values
boolqualifiers()
Every qualifier that has at least one action, in the order they were first seen — which is the order a connector was added.
public
qualifiers() : array<int, string>
Return values
array<int, string>resolve()
Resolves however a chat spelled a command, in either of the two forms a surface may use.
public
resolve(array<int, string> $words) : Action, 1: list}
A chat drops the group (twitch title); Discord keeps it (twitch channel title). Both have to find the same action, and neither may find
one that was never qualified at all.
Parameters
- $words : array<int, string>
-
The message, already split.
Return values
Action, 1: listThe action and what was left over.
normalise()
Collapses whitespace so `twitch title` and `twitch title` are one key.
private
static normalise(string $key) : string
Parameters
- $key : string