ChannelActions
in package
implements
ProvidesActions
uses
UsesTwitch
Reading and editing the channel: title, category, tags, and the rest of what `PATCH /channels` accepts.
Each of these reads with no argument and writes with one, which is the shape
chat commands have had since long before Helix and is worth matching:
!title asks, !title Back in ten tells.
All writes go through the bot's own token, so the bot account must hold
channel:manage:broadcast on the channel being edited — it is the
broadcaster, or an editor on it. When it is not, Twitch's refusal is
translated in explain() rather than surfaced raw, because the raw one
("401 Unauthorized") sends people looking in entirely the wrong place.
Tags
Table of Contents
Interfaces
- ProvidesActions
- A connector that brings commands of its own.
Constants
- TITLE_LIMIT : mixed = 140
- Twitch truncates a title past 140 characters.
Methods
- actions() : array<int, Action>
- Every command this connector defines.
- channel() : PromiseInterface<string|int, string>
- current() : PromiseInterface<string|int, object>
- The channel this action acts on.
- explain() : Throwable
- Turns Twitch's refusal into something actionable.
- 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.
- game() : PromiseInterface<string|int, string>
- modify() : PromiseInterface<string|int, null>
- requireWrite() : void
- Editing a channel is gated to the broadcaster, on both platforms, which on Discord means the server owner or an Administrator.
- tags() : PromiseInterface<string|int, string>
- title() : PromiseInterface<string|int, string>
- twitch() : TwitchConnector
Constants
TITLE_LIMIT
Twitch truncates a title past 140 characters.
private
mixed
TITLE_LIMIT
= 140
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>channel()
private
channel(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>current()
The channel this action acts on.
private
current(Context $context) : PromiseInterface<string|int, object>
Parameters
- $context : Context
Return values
PromiseInterface<string|int, object>explain()
Turns Twitch's refusal into something actionable.
private
explain(Throwable $e, Context $context) : Throwable
A 401 here almost never means the token is bad — the same token just read the channel successfully. It means the bot account is not the broadcaster and is not an editor on that channel, which is a completely different fix from the one "unauthorized" suggests.
Parameters
- $e : Throwable
- $context : Context
Return values
Throwableexplained()
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
Throwablegame()
private
game(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>modify()
private
modify(Context $context, array<string, mixed> $fields) : PromiseInterface<string|int, null>
Parameters
- $context : Context
- $fields : array<string, mixed>
Return values
PromiseInterface<string|int, null>requireWrite()
Editing a channel is gated to the broadcaster, on both platforms, which on Discord means the server owner or an Administrator.
private
requireWrite(Context $context) : void
Parameters
- $context : Context
tags()
private
tags(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>title()
private
title(Context $context, Arguments $arguments) : PromiseInterface<string|int, string>
Parameters
Return values
PromiseInterface<string|int, string>twitch()
private
twitch(Context $context) : TwitchConnector
Parameters
- $context : Context