肯德基疯狂星期四文案指令新增支持群消息

This commit is contained in:
李寻欢
2023-12-22 09:58:27 +08:00
parent 3fcbbd3308
commit 6d127d1492
5 changed files with 86 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package model
import (
"encoding/xml"
"go-wechat/types"
"regexp"
"strings"
)
@@ -99,3 +100,28 @@ func (m Message) IsPrivateText() bool {
// 发信人不以@chatroom结尾且消息类型为文本
return !strings.HasSuffix(m.FromUser, "chatroom") && m.Type == types.MsgTypeText
}
// CleanContentStartWith
// @description: 判断是否包含指定消息前缀
// @receiver m
// @param prefix
// @return bool
func (m Message) CleanContentStartWith(prefix string) bool {
content := m.Content
// 如果是@消息,过滤掉@的内容
if m.IsAt() {
re := regexp.MustCompile(`@([^| ]+)`)
matches := re.FindStringSubmatch(content)
if len(matches) > 0 {
// 过滤掉第一个匹配到的
content = strings.Replace(content, matches[0], "", 1)
}
}
// 去掉最前面的空格
content = strings.TrimLeft(content, "")
content = strings.TrimLeft(content, " ")
return strings.HasPrefix(content, prefix)
}