修复判断@消息的bug 🐛

This commit is contained in:
eatmoreapple 2021-09-29 18:33:29 +08:00
parent 6cd4fccba0
commit 851f4ed63e

View File

@ -12,11 +12,10 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"unicode"
) )
type Message struct { type Message struct {
IsAt bool isAt bool
AppInfo struct { AppInfo struct {
Type int Type int
AppID string AppID string
@ -362,11 +361,10 @@ func (m *Message) init(bot *Bot) {
displayName = receiver.NickName displayName = receiver.NickName
} }
// 判断是不是@消息 // 判断是不是@消息
atFlag := "@" + displayName atFlag := "@" + displayName + "\u2005"
index := len(atFlag) + 1 + 1 if strings.Contains(m.Content, atFlag) {
if strings.HasPrefix(m.Content, atFlag) && unicode.IsSpace(rune(m.Content[index])) { m.isAt = true
m.IsAt = true m.Content = strings.Replace(m.Content, atFlag, "", -1)
m.Content = m.Content[index+1:]
} }
} }
} }
@ -651,3 +649,8 @@ func (m *Message) IsComeFromGroup() bool {
func (m *Message) String() string { func (m *Message) String() string {
return fmt.Sprintf("<%s:%s>", m.MsgType, m.MsgId) return fmt.Sprintf("<%s:%s>", m.MsgType, m.MsgId)
} }
// IsAt 判断消息是否为@消息
func (m *Message) IsAt() bool {
return m.isAt
}