DiscordPHP-BridgeBot Documentation

ChatDispatcher
in package

FinalYes

Runs commands typed in a connector's own chat — Twitch chat, a Telegram group.

Every chat surface needs the same thing: split the line, find the action, check the rung, honour the cooldown, work out what it acts on, run it, say the answer. Writing that once per connector is how two of them end up disagreeing about a permission, so a connector only supplies what it alone knows — who is asking and where, in a ChatInvocation — and a way to reply.

Commands that cross networks

The point of one bot is that !telegram send hi typed in Twitch chat says "hi" in the Telegram group. That needs care: the command belongs to Telegram but was typed in a Twitch room, so the Twitch room's id means nothing to it. The target is found by following the bridges through Discord instead — the Twitch room is bridged to a Discord channel, which is bridged to a Telegram group, and that group is the one meant.

When that walk finds more than one — the Twitch room feeds two Discord channels bridged to two different groups — nothing is guessed. The action gets no target and says it could not work out which one was meant, which is far better than posting into the wrong community.

Tags
author

Valithor Obsidion valithor@discordphp.org

Table of Contents

Properties

$bot  : Bot
$connector  : Connector

Methods

__construct()  : mixed
bridgedThroughDiscord()  : string|null
The one room on `$network` that this chat's room reaches through Discord, or `null` when there is none or more than one.
contextFor()  : PromiseInterface<string|int, Context>
What an action typed here acts on.
dispatch()  : bool
Runs a line of chat if it is a command, and reports whether it was.
isCommand()  : bool
Whether a line of chat is addressed to the bot.
fail()  : void
isQualifier()  : bool
listUnder()  : string
What somebody who typed a bare qualifier probably wanted.
settle()  : PromiseInterface<string|int, mixed>
words()  : array<int, string>|null

Properties

Methods

bridgedThroughDiscord()

The one room on `$network` that this chat's room reaches through Discord, or `null` when there is none or more than one.

public bridgedThroughDiscord(string $room, string $network) : string|null
Parameters
$room : string
$network : string
Return values
string|null

dispatch()

Runs a line of chat if it is a command, and reports whether it was.

public dispatch(string $text, ChatInvocation $who, callable(string): mixed $reply) : bool
Parameters
$text : string
$who : ChatInvocation
$reply : callable(string): mixed

How to answer in the chat it came from.

Return values
bool

isCommand()

Whether a line of chat is addressed to the bot.

public isCommand(string $text) : bool

Only a registered command counts. Chat is full of ! — "yes!!!", or another bot's !drop — and treating all of it as a command would quietly stop relaying a slice of ordinary conversation. A bare qualifier counts, because the bot answers it with a list.

Parameters
$text : string
Return values
bool

fail()

private fail(Action $action, Throwable $e, callable(string): mixed $reply) : void
Parameters
$action : Action
$e : Throwable
$reply : callable(string): mixed

isQualifier()

private isQualifier(string $word) : bool
Parameters
$word : string
Return values
bool

listUnder()

What somebody who typed a bare qualifier probably wanted.

private listUnder(string $qualifier, Access $access) : string
Parameters
$qualifier : string
$access : Access
Return values
string

settle()

private settle(mixed $result) : PromiseInterface<string|int, mixed>
Parameters
$result : mixed
Return values
PromiseInterface<string|int, mixed>

words()

private words(string $text) : array<int, string>|null
Parameters
$text : string
Return values
array<int, string>|null —

The words after the prefix, or null when there is no prefix.

On this page

Search results