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

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

@@ -4,6 +4,7 @@ import (
"go-wechat/plugin"
"go-wechat/plugin/plugins/command"
"go-wechat/utils"
"regexp"
"strings"
)
@@ -11,13 +12,27 @@ import (
// @description: 自定义指令
// @param m
func Command(m *plugin.MessageContext) {
// 如果是群聊,提取出消息
content := m.Content
if m.IsGroup() {
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, " ")
}
// 判断是不是指令
if !strings.HasPrefix(m.Content, "/") {
if !strings.HasPrefix(content, "/") {
return
}
// 用空格分割消息下标0表示指令
msgArray := strings.Split(m.Content, " ")
msgArray := strings.Split(content, " ")
cmd := msgArray[0]
switch cmd {