2023-12-20 15:42:50 +08:00
|
|
|
|
package plugins
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"go-wechat/plugin"
|
2023-12-21 17:05:21 +08:00
|
|
|
|
"go-wechat/plugin/plugins/command"
|
2023-12-20 15:42:50 +08:00
|
|
|
|
"go-wechat/utils"
|
2023-12-22 09:58:27 +08:00
|
|
|
|
"regexp"
|
2023-12-20 15:42:50 +08:00
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Command
|
|
|
|
|
// @description: 自定义指令
|
|
|
|
|
// @param m
|
|
|
|
|
func Command(m *plugin.MessageContext) {
|
2023-12-22 09:58:27 +08:00
|
|
|
|
// 如果是群聊,提取出消息
|
|
|
|
|
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, " ")
|
|
|
|
|
}
|
2023-12-20 15:42:50 +08:00
|
|
|
|
// 判断是不是指令
|
2023-12-22 09:58:27 +08:00
|
|
|
|
if !strings.HasPrefix(content, "/") {
|
2023-12-20 15:42:50 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用空格分割消息,下标0表示指令
|
2023-12-22 09:58:27 +08:00
|
|
|
|
msgArray := strings.Split(content, " ")
|
2023-12-20 15:42:50 +08:00
|
|
|
|
cmd := msgArray[0]
|
|
|
|
|
|
|
|
|
|
switch cmd {
|
|
|
|
|
case "/帮助", "/h", "/help", "/?", "/?":
|
2023-12-21 17:05:21 +08:00
|
|
|
|
command.HelpCmd(m)
|
|
|
|
|
case "/雷神", "/ls":
|
|
|
|
|
command.LeiGodCmd(m.FromUser, msgArray[1], msgArray[2:]...)
|
|
|
|
|
case "/肯德基", "/kfc":
|
|
|
|
|
command.KfcCrazyThursdayCmd(m.FromUser)
|
2023-12-20 15:42:50 +08:00
|
|
|
|
default:
|
|
|
|
|
utils.SendMessage(m.FromUser, m.GroupUser, "指令错误", 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 中止后续消息处理
|
|
|
|
|
m.Abort()
|
|
|
|
|
}
|