bot contesta con e2ee
This commit is contained in:
+15
-7
@@ -9,8 +9,9 @@ import (
|
||||
|
||||
// ParseOptions configures how messages are parsed.
|
||||
type ParseOptions struct {
|
||||
CommandPrefix string // e.g. "!"
|
||||
BotUserID string // for mention detection
|
||||
CommandPrefix string // e.g. "!"
|
||||
BotUserID string // for mention detection, e.g. "@bot:server"
|
||||
MentionedUserIDs []string // pre-extracted from m.mentions event field (modern Matrix spec)
|
||||
}
|
||||
|
||||
// Parse converts a raw Matrix message body into a structured MessageContext. Pure.
|
||||
@@ -23,11 +24,18 @@ func Parse(body, senderID, roomID string, powerLevel int, isDM bool, opts ParseO
|
||||
IsDirectMsg: isDM,
|
||||
}
|
||||
|
||||
// Detect mention
|
||||
if opts.BotUserID != "" && strings.Contains(body, opts.BotUserID) {
|
||||
ctx.IsMention = true
|
||||
body = strings.ReplaceAll(body, opts.BotUserID, "")
|
||||
body = strings.TrimSpace(body)
|
||||
// Detect mention: check m.mentions list first (modern Matrix spec).
|
||||
if opts.BotUserID != "" {
|
||||
for _, uid := range opts.MentionedUserIDs {
|
||||
if uid == opts.BotUserID {
|
||||
ctx.IsMention = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// Fallback: check if full user ID appears in the plain text body.
|
||||
if !ctx.IsMention && strings.Contains(body, opts.BotUserID) {
|
||||
ctx.IsMention = true
|
||||
}
|
||||
}
|
||||
|
||||
// Parse command
|
||||
|
||||
Reference in New Issue
Block a user