TelegramAdapter
in package
Runs the whole catalogue from a Telegram chat.
The whole catalogue, as in every chat: !twitch title typed in a Telegram
group sets the title of the Twitch channel that group is bridged to through
Discord. Everything but the Telegram-specific parts is the core's
ChatDispatcher, so access, cooldowns and cross-network targets behave
exactly as they do everywhere else.
What only this class knows is where Telegram keeps rank. A message says nothing about its sender's standing, so it is asked for — once per person per chat per minute, and only for a line that is actually a command, since the lookup is an API call against the same budget as everything else.
Tags
Table of Contents
Constants
- RANK_TTL : mixed = 60.0
- How long a rank is trusted before it is asked for again, in seconds.
- RANK_CACHE : mixed = 500
- How many ranks to remember.
Properties
- $clock : callable(): float
- $connector : TelegramConnector
- $dispatcher : ChatDispatcher
- $ranks : array<string, Access, 1: float}>
Methods
- __construct() : mixed
- accessFor() : Access
- A `ChatMember` status as a rung.
- handle() : bool
- Runs a message if it is a command, reporting whether it was.
- isCommand() : bool
- Whether a line is addressed to the bot, as the relay needs to know.
- rank() : PromiseInterface<string|int, Access>
- Where the sender stands, on the one ladder.
- unaddressed() : string
- Drops the `@botname` Telegram appends to a command in a group.
- nameOf() : string
Constants
RANK_TTL
How long a rank is trusted before it is asked for again, in seconds.
public
mixed
RANK_TTL
= 60.0
RANK_CACHE
How many ranks to remember.
private
mixed
RANK_CACHE
= 500
Properties
$clock read-only
private
callable(): float
$clock
$connector read-only
private
TelegramConnector
$connector
$dispatcher read-only
private
ChatDispatcher
$dispatcher
$ranks
private
array<string, Access, 1: float}>
$ranks
= []
"chat:user" => rank, and when it was read
Methods
__construct()
public
__construct(TelegramConnector $connector, Bot $bot[, callable(): float|null $clock = null ]) : mixed
Parameters
- $connector : TelegramConnector
- $bot : Bot
- $clock : callable(): float|null = null
-
For tests; defaults to the wall clock.
accessFor()
A `ChatMember` status as a rung.
public
static accessFor(string $status) : Access
Parameters
- $status : string
Return values
Accesshandle()
Runs a message if it is a command, reporting whether it was.
public
handle(Message $message) : bool
The answer is threaded onto the command it answers, through the connector's paced queue.
Parameters
- $message : Message
Return values
boolisCommand()
Whether a line is addressed to the bot, as the relay needs to know.
public
isCommand(string $text) : bool
Parameters
- $text : string
Return values
boolrank()
Where the sender stands, on the one ladder.
public
rank(Message $message) : PromiseInterface<string|int, Access>
- The configured owner is the operator, wherever they type.
- A chat's creator is its administrator, and its administrators are moderators — the same shape as a Twitch broadcaster and their mods.
- Somebody posting as the chat itself — an anonymous group admin, or a channel post — is an administrator of it by definition, so a moderator.
- Anyone else, and anyone in a private chat with the bot, is everyone.
A lookup that fails is everyone: refusing a command is recoverable, granting one is not.
Parameters
- $message : Message
Return values
PromiseInterface<string|int, Access>unaddressed()
Drops the `@botname` Telegram appends to a command in a group.
public
unaddressed(string $text) : string
Telegram's own command menu sends /twitch@SomeBot title when several
bots share a group; with a / prefix configured, that has to reach the
dispatcher as /twitch title. A command addressed to a different bot
is left alone, and so is not a command at all.
Parameters
- $text : string
Return values
stringnameOf()
private
nameOf(Message $message) : string
Parameters
- $message : Message