From db62b9a1d875f654eec845c19d7309832d6af576 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 29 Apr 2025 02:26:50 +0300 Subject: [PATCH] commands: ignore notices --- commands/event.go | 6 ++++++ commands/processor.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/commands/event.go b/commands/event.go index 10d6283f..c02bd3b9 100644 --- a/commands/event.go +++ b/commands/event.go @@ -58,10 +58,16 @@ var IDHTMLParser = &format.HTMLParser{ // ParseEvent parses a message into a command event struct. func ParseEvent[MetaType any](ctx context.Context, evt *event.Event) *Event[MetaType] { content := evt.Content.Parsed.(*event.MessageEventContent) + if content.MsgType == event.MsgNotice || content.RelatesTo.GetReplaceID() != "" { + return nil + } text := content.Body if content.Format == event.FormatHTML { text = IDHTMLParser.Parse(content.FormattedBody, format.NewContext(ctx)) } + if len(text) == 0 { + return nil + } parts := strings.Fields(text) return &Event[MetaType]{ Event: evt, diff --git a/commands/processor.go b/commands/processor.go index 1e0a99a2..cc55aceb 100644 --- a/commands/processor.go +++ b/commands/processor.go @@ -62,7 +62,7 @@ func (proc *Processor[MetaType]) Process(ctx context.Context, evt *event.Event) } }() parsed := ParseEvent[MetaType](ctx, evt) - if !proc.PreValidator.Validate(parsed) { + if parsed == nil || !proc.PreValidator.Validate(parsed) { return } parsed.Proc = proc