ModerationActions
in package
implements
ProvidesActions
uses
UsesTwitch
Moderation, chat settings and the broadcast controls.
Everything here acts as the bot's own account in its capacity as a moderator,
so moderator_id is always the bot's user id — Twitch requires the moderator
to be the authenticated user, and a token cannot moderate on someone else's
behalf.
These are the commands with real consequences, so the permission rungs are set deliberately rather than uniformly: timing someone out is a moderator's job, but handing out the moderator badge, raiding, and running an ad break are the broadcaster's.
Tags
Table of Contents
Interfaces
- ProvidesActions
- A connector that brings commands of its own.
Constants
- MAX_TIMEOUT : mixed = 1209600
- Twitch caps a timeout at fourteen days.
Methods
- actions() : array<int, Action>
- Every command this connector defines.
- announce() : PromiseInterface<string|int, string>
- attributed() : string
- An announcement's text, saying who sent it and from where when that was not Twitch.
- ban() : PromiseInterface<string|int, string>
- clear() : PromiseInterface<string|int, string>
- commercial() : PromiseInterface<string|int, string>
- emoteonly() : 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.
- followersonly() : PromiseInterface<string|int, string>
- isOff() : bool
- mod() : PromiseInterface<string|int, string>
- moderatorId() : string
- The bot's own user id.
- onUser() : PromiseInterface<string|int, string>
- Resolves the first argument to a Twitch user, then runs `$then`.
- raid() : PromiseInterface<string|int, string>
- reason() : string
- The reason for a moderation action, from whichever form supplied it.
- settings() : PromiseInterface<string|int, mixed>
- shoutout() : PromiseInterface<string|int, string>
- slow() : PromiseInterface<string|int, string>
- subonly() : PromiseInterface<string|int, string>
- timeout() : PromiseInterface<string|int, string>
- twitch() : TwitchConnector
- unban() : PromiseInterface<string|int, string>
- unmod() : PromiseInterface<string|int, string>
- unraid() : PromiseInterface<string|int, string>
- unvip() : PromiseInterface<string|int, string>
- vip() : PromiseInterface<string|int, string>
Constants
MAX_TIMEOUT
Twitch caps a timeout at fourteen days.
private
mixed
MAX_TIMEOUT
= 1209600
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>announce()
private
announce(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>attributed()
An announcement's text, saying who sent it and from where when that was not Twitch.
private
static attributed(Context $context, string $text) : string
Twitch shows every announcement as the host's. Typed in Twitch chat, the command that made it is right above it; typed in Discord or Telegram, nothing would say it came from someone else, so it says so the way relayed chat does. The name is defused the same way too (F2).
Parameters
- $context : Context
- $text : string
Return values
stringban()
private
ban(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>clear()
private
clear(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>commercial()
private
commercial(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>emoteonly()
private
emoteonly(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
Throwablefollowersonly()
private
followersonly(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>isOff()
private
isOff(string $value) : bool
Parameters
- $value : string
Return values
boolmod()
private
mod(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>moderatorId()
The bot's own user id.
private
moderatorId(Context $context) : string
Twitch requires moderator_id to be the authenticated user, so this is
never the person who typed the command — a distinction worth keeping in
mind when reading the audit log, where every action is attributed to the
bot account.
Parameters
- $context : Context
Return values
stringonUser()
Resolves the first argument to a Twitch user, then runs `$then`.
private
onUser(Context $context, Arguments $arguments, callable(string, array<string, mixed>): PromiseInterface $then) : PromiseInterface<string|int, string>
Everything here names a person, and naming the wrong one bans the wrong person, so an unresolvable login stops the command rather than being passed on to Helix to interpret.
Parameters
- $context : Context
- $arguments : Arguments
- $then : callable(string, array<string, mixed>): PromiseInterface
Return values
PromiseInterface<string|int, string>raid()
private
raid(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>reason()
The reason for a moderation action, from whichever form supplied it.
private
reason(Arguments $arguments, int $from) : string
The named value wins. A slash command omits an unsupplied optional
entirely, so /timeout user:bob reason:spam — no seconds — leaves a
gap that stops positional recording at bob; reading positionally alone
would silently drop the reason and log the ban as unexplained.
Parameters
- $arguments : Arguments
- $from : int
Return values
stringsettings()
private
settings(Context $context, array<string, mixed> $fields) : PromiseInterface<string|int, mixed>
Parameters
- $context : Context
- $fields : array<string, mixed>
Return values
PromiseInterface<string|int, mixed>shoutout()
private
shoutout(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>slow()
private
slow(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>subonly()
private
subonly(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>timeout()
private
timeout(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>twitch()
private
twitch(Context $context) : TwitchConnector
Parameters
- $context : Context
Return values
TwitchConnectorunban()
private
unban(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>unmod()
private
unmod(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>unraid()
private
unraid(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>unvip()
private
unvip(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>vip()
private
vip(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>