添加消息处理

This commit is contained in:
Noth Amor
2022-07-18 20:10:54 +08:00
parent 974ceb5b3d
commit fcc221ff42
3 changed files with 15 additions and 4 deletions

9
controller/msg.go Normal file
View File

@@ -0,0 +1,9 @@
package controller
import (
"github.com/eatmoreapple/openwechat"
)
func SingleChoice(msg *openwechat.Message) {
msg.ReplyText("我执行成功了")
}

2
go.mod
View File

@@ -2,4 +2,4 @@ module go-bot/bot
go 1.18
require github.com/eatmoreapple/openwechat v1.1.11 // indirect
require github.com/eatmoreapple/openwechat v1.1.11

View File

@@ -2,17 +2,19 @@ package main
import (
"fmt"
"go-bot/bot/controller"
"github.com/eatmoreapple/openwechat"
)
func main() {
bot := openwechat.DefaultBot(openwechat.Desktop)
// bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式,上面登录不上的可以尝试切换这种模式
// 注册消息处理函数
bot.MessageHandler = func(msg *openwechat.Message) {
if msg.IsText() && msg.Content == "ping" {
msg.ReplyText("pong")
if msg.IsText() && msg.Content == "专升本英语选择题" {
controller.SingleChoice(msg)
}
}
// 注册登陆二维码回调