ApiActions
in package
implements
ProvidesActions
uses
UsesTwitch
`api` — the rest of Helix.
The named commands elsewhere in this directory cover what a chat actually asks for day to day. This covers everything else: every method of every TwitchPHP repository, reachable by name, with arguments matched to parameters and the response rendered back into chat.
api list every repository
api list moderation every call on one
api help moderation.warn its signature
api moderation.warn broadcaster_id=1 moderator_id=2 user_id=3 reason=spam
Gated to Access::Operator — not to the broadcaster, and not to moderators. This reaches endpoints that ban users, end streams and rewrite a channel, and it does so with the bot's own token; the rung below it is a badge anyone can be given by someone who is not thinking about that.
Tags
Table of Contents
Interfaces
- ProvidesActions
- A connector that brings commands of its own.
Constants
- MAX_RENDER : mixed = 1500
- Rendered responses are trimmed to this before the surface's own limit.
Methods
- actions() : array<int, Action>
- Every command this connector defines.
- api() : PromiseInterface|string
- call() : PromiseInterface<string|int, string>
- explained() : callable(Context, Arguments): mixed
- Wraps a handler so a Helix refusal reaches whoever typed the command as a sentence, rather than as "that did not work".
- explainTwitch() : Throwable
- What Twitch's refusal means to the person who asked.
- help() : string
- list() : string
- namedFor() : array<string, string>
- The `key=value` arguments for the call.
- normalize() : mixed
- Flattens Parts and Collections into plain arrays.
- render() : string
- Renders whatever a repository handed back.
- twitch() : TwitchConnector
Constants
MAX_RENDER
Rendered responses are trimmed to this before the surface's own limit.
private
mixed
MAX_RENDER
= 1500
Methods
actions()
Every command this connector defines.
public
actions() : array<int, Action>
Each one's qualifier must be the connector's own Connector::name(); ActionRegistry refuses anything else, because a connector claiming another's qualifier is how two packages end up silently shadowing each other's commands.
Return values
array<int, Action>api()
private
api(Context $context, Arguments $arguments) : PromiseInterface|string
Parameters
Return values
PromiseInterface|stringcall()
private
call(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>explained()
Wraps a handler so a Helix refusal reaches whoever typed the command as a sentence, rather than as "that did not work".
private
explained(callable(Context, Arguments): mixed $handler) : callable(Context, Arguments): mixed
Parameters
Return values
callable(Context, Arguments): mixedexplainTwitch()
What Twitch's refusal means to the person who asked.
private
static explainTwitch(Throwable $e) : Throwable
A 4xx from Helix carries a message written for people — "The user specified in the user_id field is already banned." — and nothing secret, so it is passed on. Anything else (a 5xx, a dropped connection) is left for the adapter to log and summarise.
Parameters
- $e : Throwable
Return values
Throwablehelp()
private
help(Context $context, Arguments $arguments) : string
Parameters
Return values
stringlist()
private
list(Context $context, Arguments $arguments) : string
Parameters
Return values
stringnamedFor()
The `key=value` arguments for the call.
private
namedFor(Arguments $arguments) : array<string, string>
The prefix form parses them out of the line already. The slash form
cannot — Discord has no option type meaning "arbitrary pairs" — so they
arrive as one args string and are parsed here with the same parser, so
both forms accept identical syntax, quoting included.
Parameters
- $arguments : Arguments
Return values
array<string, string>normalize()
Flattens Parts and Collections into plain arrays.
private
normalize(mixed $result) : mixed
Repositories return rich objects; json_encode on one of those would
either expose internals or produce }, depending on the class.
Parameters
- $result : mixed
render()
Renders whatever a repository handed back.
private
render(Context $context, string $call, mixed $result) : string
Everything is passed through Sensitive::redact() first — not only the calls on the denylist. That list is a judgement about today's API and will age; the field-level pass is what catches the endpoint nobody thought about, including ones added to TwitchPHP after this was written.
Parameters
- $context : Context
- $call : string
- $result : mixed
Return values
stringtwitch()
private
twitch(Context $context) : TwitchConnector
Parameters
- $context : Context