Compare commits

..

No commits in common. "710aa535623866d6c48cd322c03eeccef45dde44" and "c1cb14b938015cc985d3baf7227c55e1abc295cd" have entirely different histories.

5 changed files with 5 additions and 86 deletions

View File

@ -5,7 +5,6 @@ import (
"go-wechat/model" "go-wechat/model"
plugin "go-wechat/plugin" plugin "go-wechat/plugin"
"go-wechat/plugin/plugins" "go-wechat/plugin/plugins"
"go-wechat/service"
) )
// Plugin // Plugin
@ -25,8 +24,8 @@ func Plugin() {
// 私聊指令消息 // 私聊指令消息
dispatcher.RegisterHandler(func(m *model.Message) bool { dispatcher.RegisterHandler(func(m *model.Message) bool {
// 私聊消息 或 群聊艾特机器人并且以/开头的消息 // 私聊消息直接进去
return (m.IsPrivateText() || (m.IsAt() && m.CleanContentStartWith("/"))) && service.CheckIsEnableCommand(m.FromUser) return m.IsPrivateText()
}, plugins.Command) }, plugins.Command)
// AI消息插件 // AI消息插件

View File

@ -3,7 +3,6 @@ package model
import ( import (
"encoding/xml" "encoding/xml"
"go-wechat/types" "go-wechat/types"
"regexp"
"strings" "strings"
) )
@ -100,28 +99,3 @@ func (m Message) IsPrivateText() bool {
// 发信人不以@chatroom结尾且消息类型为文本 // 发信人不以@chatroom结尾且消息类型为文本
return !strings.HasSuffix(m.FromUser, "chatroom") && m.Type == types.MsgTypeText 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)
}

View File

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

View File

@ -10,14 +10,11 @@ import (
// @description: 肯德基疯狂星期四文案 // @description: 肯德基疯狂星期四文案
// @param userId string 发信人 // @param userId string 发信人
func KfcCrazyThursdayCmd(userId string) { func KfcCrazyThursdayCmd(userId string) {
// 随机选一个接口调用 // 接口调用
str := kfcApi1() str := kfcApi1()
if str == "" { if str == "" {
str = kfcApi2() str = kfcApi2()
} }
if str == "" {
str = kfcApi3()
}
if str == "" { if str == "" {
str = "文案获取失败" str = "文案获取失败"
} }
@ -67,29 +64,3 @@ func kfcApi2() string {
} }
return resp.String() return resp.String()
} }
// kfcApi3
// @description: 肯德基疯狂星期四文案接口3
// @return string
func kfcApi3() string {
type result struct {
Code int `json:"code"`
Msg string `json:"msg"`
Text string `json:"text"`
}
var resData result
res := resty.New()
resp, err := res.R().
SetResult(&resData).
Post("https://api.pearktrue.cn/api/kfc")
if err != nil {
log.Panicf("KFC接口3文案获取失败: %s", err.Error())
}
log.Printf("KFC接口3文案获取结果: %s", resp.String())
if resData.Text != "" {
return resData.Text
}
return resp.String()
}

View File

@ -50,13 +50,3 @@ func GetAllEnableChatRank() (records []entity.Friend, err error) {
err = client.MySQL.Where("enable_chat_rank = ?", 1).Where("wxid LIKE '%@chatroom'").Find(&records).Error err = client.MySQL.Where("enable_chat_rank = ?", 1).Where("wxid LIKE '%@chatroom'").Find(&records).Error
return return
} }
// CheckIsEnableCommand
// @description: 检查用户是否启用了指令
// @param userId
// @return flag
func CheckIsEnableCommand(userId string) (flag bool) {
var coo int64
client.MySQL.Model(&entity.Friend{}).Where("enable_command = 1").Where("wxid = ?", userId).Count(&coo)
return coo > 0
}