Add MSC4391 support

Fixes #133
This commit is contained in:
Henry Hiles 2026-11-03 13:12:58 -05:00
commit 3fc33a5ac9
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -0,0 +1,36 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/bot_command_description.dart";
part "bot_command.freezed.dart";
@Freezed(toJson: false, fromJson: false)
class const BotCommand({
required final String sender,
required final String botName,
final Uri? botAvatar,
required final BotCommandDescriptionContent description,
}) with _$BotCommand {
/// Commands gomuks handles itself, which bots can't override.
static const builtIn = ISetConst({
"me",
"notice",
"timestamp",
"unencrypted",
"rawinputbody",
"rainbow",
"plain",
"html",
"htmlmd",
});
String get prefix => "/${description.command}";
String get about => [botName, ?description.description].join(" · ");
bool completes(String text) =>
text.startsWith("/") &&
(prefix.startsWith(text) || argumentsIn(text) != null);
String? argumentsIn(String text) =>
text.startsWith("$prefix ") ? text.substring(prefix.length + 1) : null;
}