From 3fcbbd3308610bd950c1ed8cf652b20d397c0676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Thu, 21 Dec 2023 17:05:21 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=B0=83=E6=95=B4=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E7=BB=93=E6=9E=84=EF=BC=8C=E6=96=B0=E5=A2=9E`?= =?UTF-8?q?=E8=82=AF=E5=BE=B7=E5=9F=BA=E7=96=AF=E7=8B=82=E6=98=9F=E6=9C=9F?= =?UTF-8?q?=E5=9B=9B=E6=96=87=E6=A1=88`=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/plugins/command.go | 60 +++-------------------- plugin/plugins/command/help.go | 29 +++++++++++ plugin/plugins/command/kfc.go | 66 ++++++++++++++++++++++++++ plugin/plugins/{ => command}/leigod.go | 34 ++++++++++++- 4 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 plugin/plugins/command/help.go create mode 100644 plugin/plugins/command/kfc.go rename plugin/plugins/{ => command}/leigod.go (88%) diff --git a/plugin/plugins/command.go b/plugin/plugins/command.go index af7f32d..b009fa0 100644 --- a/plugin/plugins/command.go +++ b/plugin/plugins/command.go @@ -2,6 +2,7 @@ package plugins import ( "go-wechat/plugin" + "go-wechat/plugin/plugins/command" "go-wechat/utils" "strings" ) @@ -21,9 +22,11 @@ func Command(m *plugin.MessageContext) { switch cmd { case "/帮助", "/h", "/help", "/?", "/?": - helpCmd(m) - case "/ls", "/雷神": - leiGodCmd(m.FromUser, msgArray[1], msgArray[2:]...) + command.HelpCmd(m) + case "/雷神", "/ls": + command.LeiGodCmd(m.FromUser, msgArray[1], msgArray[2:]...) + case "/肯德基", "/kfc": + command.KfcCrazyThursdayCmd(m.FromUser) default: utils.SendMessage(m.FromUser, m.GroupUser, "指令错误", 0) } @@ -31,54 +34,3 @@ func Command(m *plugin.MessageContext) { // 中止后续消息处理 m.Abort() } - -// helpCmd -// @description: 帮助指令 -func helpCmd(m *plugin.MessageContext) { - str := `帮助菜单: -指令消息必须以'/'开头,比如: '/帮助'。 -支持的指令: - -#1. 雷神加速器 -/ls option args -option: 指令选项,可选值: - 绑定账户:'绑定'、'b',参数: 账户名 密码 [-f],-f表示强制绑定,非必传项 - 详情: '详情'、'i' - 暂停: '暂停'、'p' -示例: 绑定: -/ls 绑定 123456 123456 或者 /ls b 123456 123456 -` - utils.SendMessage(m.FromUser, m.GroupUser, str, 0) - -} - -// leiGodCmd -// @description: 雷神加速器指令 -// @param userId -// @param cmd -// @param args -// @return string -func leiGodCmd(userId, cmd string, args ...string) { - lg := newLeiGod(userId) - - var replyMsg string - switch cmd { - case "绑定", "b": - var force bool - if len(args) == 3 && args[2] == "-f" { - force = true - } - replyMsg = lg.binding(args[0], args[1], force) - case "详情", "i": - replyMsg = lg.info() - case "暂停", "p": - replyMsg = lg.pause() - default: - replyMsg = "指令错误" - } - - // 返回消息 - if strings.TrimSpace(replyMsg) != "" { - utils.SendMessage(userId, "", replyMsg, 0) - } -} diff --git a/plugin/plugins/command/help.go b/plugin/plugins/command/help.go new file mode 100644 index 0000000..c469c36 --- /dev/null +++ b/plugin/plugins/command/help.go @@ -0,0 +1,29 @@ +package command + +import ( + "go-wechat/plugin" + "go-wechat/utils" +) + +// HelpCmd +// @description: 帮助指令 +func HelpCmd(m *plugin.MessageContext) { + str := `帮助菜单: +指令消息必须以'/'开头,比如: '/帮助'。 +支持的指令: + +#1. 雷神加速器 +/ls option args +option: 指令选项,可选值: + 绑定账户:'绑定'、'b',参数: 账户名 密码 [-f],-f表示强制绑定,非必传项 + 详情: '详情'、'i' + 暂停: '暂停'、'p' +示例: 绑定: +/ls 绑定 123456 123456 或者 /ls b 123456 123456 + +#2. 肯德基疯狂星期四文案 +/kfc、/肯德基 +` + utils.SendMessage(m.FromUser, m.GroupUser, str, 0) + +} diff --git a/plugin/plugins/command/kfc.go b/plugin/plugins/command/kfc.go new file mode 100644 index 0000000..5ca4d9f --- /dev/null +++ b/plugin/plugins/command/kfc.go @@ -0,0 +1,66 @@ +package command + +import ( + "github.com/go-resty/resty/v2" + "go-wechat/utils" + "log" +) + +// KfcCrazyThursdayCmd +// @description: 肯德基疯狂星期四文案 +// @param userId string 发信人 +func KfcCrazyThursdayCmd(userId string) { + // 接口调用 + str := kfcApi1() + if str == "" { + str = kfcApi2() + } + if str == "" { + str = "文案获取失败" + } + + // 发送消息 + utils.SendMessage(userId, "", str, 0) +} + +// kfcApi1 +// @description: 肯德基疯狂星期四文案接口1 +// @return string +func kfcApi1() string { + res := resty.New() + resp, err := res.R(). + Post("https://api.jixs.cc/api/wenan-fkxqs/index.php") + if err != nil { + log.Panicf("KFC接口1文案获取失败: %s", err.Error()) + } + log.Printf("KFC接口1文案获取结果: %s", resp.String()) + return resp.String() +} + +// kfcApi2 +// @description: 肯德基疯狂星期四文案接口2 +// @return string +func kfcApi2() string { + type result struct { + Code int `json:"code"` + Text string `json:"text"` + Data struct { + Msg string `json:"msg"` + } `json:"data"` + } + + var resData result + + res := resty.New() + resp, err := res.R(). + SetResult(&resData). + Post("https://api.jixs.cc/api/wenan-fkxqs/index.php") + if err != nil { + log.Panicf("KFC接口2文案获取失败: %s", err.Error()) + } + log.Printf("KFC接口2文案获取结果: %s", resp.String()) + if resData.Data.Msg != "" { + return resData.Data.Msg + } + return resp.String() +} diff --git a/plugin/plugins/leigod.go b/plugin/plugins/command/leigod.go similarity index 88% rename from plugin/plugins/leigod.go rename to plugin/plugins/command/leigod.go index 4ecd8eb..db5e66d 100644 --- a/plugin/plugins/leigod.go +++ b/plugin/plugins/command/leigod.go @@ -1,4 +1,4 @@ -package plugins +package command import ( "encoding/json" @@ -11,6 +11,7 @@ import ( "go-wechat/vo" "gorm.io/gorm" "log" + "strings" ) // leiGod @@ -33,6 +34,37 @@ func newLeiGod(userId string) leiGodI { return &leiGod{userId: userId} } +// LeiGodCmd +// @description: 雷神加速器指令 +// @param userId +// @param cmd +// @param args +// @return string +func LeiGodCmd(userId, cmd string, args ...string) { + lg := newLeiGod(userId) + + var replyMsg string + switch cmd { + case "绑定", "b": + var force bool + if len(args) == 3 && args[2] == "-f" { + force = true + } + replyMsg = lg.binding(args[0], args[1], force) + case "详情", "i": + replyMsg = lg.info() + case "暂停", "p": + replyMsg = lg.pause() + default: + replyMsg = "指令错误" + } + + // 返回消息 + if strings.TrimSpace(replyMsg) != "" { + utils.SendMessage(userId, "", replyMsg, 0) + } +} + // binding // @description: 绑定雷神加速器账号 // @receiver l