From 386889981f5ac3a5e37fdbd63c3d1474bc2d3cfd Mon Sep 17 00:00:00 2001 From: timedout Date: Thu, 8 Jan 2026 13:10:32 +0000 Subject: [PATCH] commands/handler: Add MakeMSC4391Event helper func --- commands/handler.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/commands/handler.go b/commands/handler.go index b01d594f..4b4a02ce 100644 --- a/commands/handler.go +++ b/commands/handler.go @@ -8,6 +8,8 @@ package commands import ( "strings" + + "maunium.net/go/mautrix/event" ) type Handler[MetaType any] struct { @@ -18,12 +20,17 @@ type Handler[MetaType any] struct { Name string // Aliases are alternative names for the command. They must be lowercase. Aliases []string + // Description is a description of the command. + Description *event.ExtensibleTextContainer // Subcommands are subcommands of this command. Subcommands []*Handler[MetaType] // PreFunc is a function that is called before checking subcommands. // It can be used to have parameters between subcommands (e.g. `!rooms `). // Event.ShiftArg will likely be useful for implementing such parameters. PreFunc func(ce *Event[MetaType]) + // Parameters are the parameters of the command. These are used to suggest auto-completions to clients, + // but are not actually functional in any regard. + Parameters []*event.MSC4391Parameter subcommandContainer *CommandContainer[MetaType] } @@ -37,6 +44,16 @@ func (h *Handler[MetaType]) initSubcommandContainer() { } } +// MakeMSC4391Event creates a *event.MSC4391BotCommandEventContent representing this command handler. +func (h *Handler[MetaType]) MakeMSC4391Event() *event.MSC4391BotCommandEventContent { + return &event.MSC4391BotCommandEventContent{ + Command: h.Name, + Aliases: h.Aliases, + Description: h.Description, + Parameters: h.Parameters, + } +} + func MakeUnknownCommandHandler[MetaType any](prefix string) *Handler[MetaType] { return &Handler[MetaType]{ Name: UnknownCommandName,