Skip to content

Commit

Permalink
feat: 预处理消息阶段移除at消息后的空格消息 (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikaCelery authored Oct 9, 2024
1 parent 5f8ad1e commit 3f1e32b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ loop:
}
break
}

}

// mid handler
Expand Down Expand Up @@ -395,8 +394,21 @@ loop:

// preprocessMessageEvent 返回信息事件
func preprocessMessageEvent(e *Event) {
e.Message = message.ParseMessage(e.NativeMessage)
msgs := message.ParseMessage(e.NativeMessage)

for i := 0; i < len(msgs)-1; i++ {
if msgs[i].Type == "at" && msgs[i+1].Type == "text" {
msgs[i+1].Data["text"] = strings.TrimSpace(msgs[i+1].Data["text"])
}
}
var filtered = make([]message.MessageSegment, 0, len(msgs))
// remove empty text segment
for i := 0; i < len(msgs); {
if msgs[i].Type != "text" || msgs[i].Data["text"] != "" {
filtered = append(filtered, msgs[i])
}
}
e.Message = filtered
processAt := func() { // 处理是否at机器人
e.IsToMe = false
for i, m := range e.Message {
Expand Down

0 comments on commit 3f1e32b

Please sign in to comment.