DiscordPHP-BridgeBot Documentation

DiscordAdapter
in package

FinalYes

Registers the action catalogue into DiscordPHP's `MessageCommandClient`, as prefix commands.

Each qualifier becomes one top-level command with a sub-command per action, so !twitch title and !telegram send are what people type — the group is dropped, because a chat has no 25-option cap to work around, but the qualifier never is. Typing the qualifier alone lists what is under it.

Everything platform-specific about the Discord side lives here: reading a member's permissions, working out which room a Discord channel stands for, and getting a reply back out without pinging the server.

Tags
author

Valithor Obsidion valithor@discordphp.org

Table of Contents

Properties

$bot  : Bot
$rankIn  : callable(Message, string): Array
$registry  : ActionRegistry

Methods

__construct()  : mixed
register()  : void
Wires every Discord-available action into the command client.
builder()  : MessageBuilder
Every outbound message: clamped to Discord's limit, and pinging nobody.
byQualifier()  : array<string, array<int, Action>>
Every Discord-available action, grouped by the command it lives under.
contextFor()  : PromiseInterface<string|int, Context>
Builds the invocation context, resolving which room this Discord channel acts on.
deliver()  : void
fail()  : void
invoke()  : void
listUnder()  : void
What somebody who typed a bare qualifier probably wanted.
rendered()  : string|MessageBuilder|null
roomOverride()  : string|null
The room somebody named in `channel=` or `target=`, when that is what it means.
route()  : void
Finds the action a line names, or lists what is under the qualifier.
say()  : void
settle()  : PromiseInterface<string|int, string|MessageBuilder|null>
Normalises a handler's return into a promise of what to send.

Properties

$rankIn read-only

private callable(Message, string): Array $rankIn

Methods

__construct()

public __construct(Bot $bot, ActionRegistry $registry[, callable(Message, string): Array|null $rankIn = null ]) : mixed
Parameters
$bot : Bot
$registry : ActionRegistry
$rankIn : callable(Message, string): Array|null = null

The author's rung in a channel of the same server, or null when they cannot see it. Defaults to reading their permissions there; injectable for tests.

register()

Wires every Discord-available action into the command client.

public register() : void

One command per qualifier, and the rest of the line is resolved by ActionRegistry::resolve() rather than by registering each action as a sub-command. That is what lets both forms work — !twitch title as a chat would type it and !twitch channel title as the slash menu shows it — and it keeps aliases and cooldowns on the same path as every other surface instead of in DiscordPHP's own copy of them.

builder()

Every outbound message: clamped to Discord's limit, and pinging nobody.

private builder(string $text) : MessageBuilder
Parameters
$text : string
Return values
MessageBuilder

byQualifier()

Every Discord-available action, grouped by the command it lives under.

private byQualifier() : array<string, array<int, Action>>
Return values
array<string, array<int, Action>>

contextFor()

Builds the invocation context, resolving which room this Discord channel acts on.

private contextFor(Action $action, Message $message, Access $access, Arguments $arguments, bool $isPublic) : PromiseInterface<string|int, Context>

The action's own qualifier picks the connector, which is what makes this work with more than one installed: twitch title acts on the Twitch room this channel is bridged to even when the same channel is also bridged to a Telegram group.

An explicit channel= or target= wins over the bridge, so a server that bridges several rooms can reach any of them from one channel — but only rooms this server has bridged, unless the operator is asking.

Parameters
$action : Action
$message : Message
$access : Access
$arguments : Arguments
$isPublic : bool
Return values
PromiseInterface<string|int, Context>

deliver()

private deliver(Message $message, string|MessageBuilder $reply, bool $private) : void
Parameters
$message : Message
$reply : string|MessageBuilder
$private : bool

fail()

private fail(Message $message, Action $action, Throwable $e) : void
Parameters
$message : Message
$action : Action
$e : Throwable

invoke()

private invoke(Action $action, Message $message, array<string|int, mixed> $args) : void
Parameters
$action : Action
$message : Message
$args : array<string|int, mixed>

listUnder()

What somebody who typed a bare qualifier probably wanted.

private listUnder(Message $message, string $qualifier) : void
Parameters
$message : Message
$qualifier : string

rendered()

private static rendered(mixed $value) : string|MessageBuilder|null
Parameters
$value : mixed
Return values
string|MessageBuilder|null

roomOverride()

The room somebody named in `channel=` or `target=`, when that is what it means.

private roomOverride(Action $action, Arguments $arguments) : string|null

An action that declares an option by that name owns it: link takes a target because that is the room to bridge with, and raid a channel because that is who to raid. Anything else is a request to act on a room other than this channel's own.

Parameters
$action : Action
$arguments : Arguments
Return values
string|null

route()

Finds the action a line names, or lists what is under the qualifier.

private route(string $qualifier, Message $message, array<string|int, mixed> $args) : void
Parameters
$qualifier : string
$message : Message
$args : array<string|int, mixed>

say()

private say(Message $message, string|MessageBuilder $text) : void
Parameters
$message : Message
$text : string|MessageBuilder

settle()

Normalises a handler's return into a promise of what to send.

private settle(mixed $result) : PromiseInterface<string|int, string|MessageBuilder|null>

A handler may answer with a string or with a MessageBuilder, for the cases a sentence will not cover — a Components v2 panel, say. Both render on Discord, which is why an action that returns a builder must declare itself Discord-only.

Parameters
$result : mixed
Return values
PromiseInterface<string|int, string|MessageBuilder|null>
On this page

Search results