🐛 修复AI插件会响应@所有人
消息事件
This commit is contained in:
parent
83efe20ddf
commit
2918924107
@ -26,13 +26,13 @@ func Plugin() {
|
||||
// 私聊指令消息
|
||||
dispatcher.RegisterHandler(func(m *model.Message) bool {
|
||||
// 私聊消息 或 群聊艾特机器人并且以/开头的消息
|
||||
return (m.IsPrivateText() || (m.IsAt() && m.CleanContentStartWith("/"))) && service.CheckIsEnableCommand(m.FromUser)
|
||||
return (m.IsPrivateText() || (m.IsAt() && !m.IsAtAll() && m.CleanContentStartWith("/"))) && service.CheckIsEnableCommand(m.FromUser)
|
||||
}, plugins.Command)
|
||||
|
||||
// AI消息插件
|
||||
dispatcher.RegisterHandler(func(m *model.Message) bool {
|
||||
// 群内@或者私聊文字消息
|
||||
return m.IsAt() || m.IsPrivateText()
|
||||
return m.IsAt() && !m.IsAtAll() || m.IsPrivateText()
|
||||
}, plugins.AI)
|
||||
|
||||
// 欢迎新成员
|
||||
|
@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"github.com/duke-git/lancet/v2/slice"
|
||||
"go-wechat/types"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -31,6 +32,21 @@ type systemMsgDataXml struct {
|
||||
Type string `xml:"type,attr"`
|
||||
}
|
||||
|
||||
// atMsgDataXml
|
||||
// @description: 微信@消息的xml结构
|
||||
type atMsgDataXml struct {
|
||||
XMLName xml.Name `xml:"msgsource"`
|
||||
Text string `xml:",chardata"`
|
||||
AtUserList string `xml:"atuserlist"`
|
||||
Silence string `xml:"silence"`
|
||||
MemberCount string `xml:"membercount"`
|
||||
Signature string `xml:"signature"`
|
||||
TmpNode struct {
|
||||
Text string `xml:",chardata"`
|
||||
PublisherID string `xml:"publisher-id"`
|
||||
} `xml:"tmp_node"`
|
||||
}
|
||||
|
||||
// sysMsg
|
||||
// @description: 消息主体
|
||||
type sysMsg struct{}
|
||||
@ -92,6 +108,22 @@ func (m Message) IsAt() bool {
|
||||
return strings.HasSuffix(m.DisplayFullContent, "在群聊中@了你")
|
||||
}
|
||||
|
||||
// IsAtAll
|
||||
// @description: 是否是At所有人的消息
|
||||
// @receiver m
|
||||
// @return bool
|
||||
func (m Message) IsAtAll() bool {
|
||||
// 解析raw里面的xml
|
||||
var d atMsgDataXml
|
||||
if err := xml.Unmarshal([]byte(m.Raw), &d); err != nil {
|
||||
return false
|
||||
}
|
||||
// 转换@用户列表为数组
|
||||
atUserList := strings.Split(d.AtUserList, ",")
|
||||
// 判断是否包含@所有人
|
||||
return slice.Contain(atUserList, "notify@all")
|
||||
}
|
||||
|
||||
// IsPrivateText
|
||||
// @description: 是否是私聊消息
|
||||
// @receiver m
|
||||
|
Loading…
Reference in New Issue
Block a user