forked from code-innovator-zyx/wechat-gptbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
48 lines (44 loc) · 1.2 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"github.com/eatmoreapple/openwechat"
"github.com/sirupsen/logrus"
"github.com/skip2/go-qrcode"
"wechat-gptbot/core"
"wechat-gptbot/core/handler"
)
/*
* @Author: zouyx
* @Email: [email protected]
* @Date: 2024/4/8 10:46
* @Package:
*/
func main() {
// 初始化核心配置
core.Initialize()
bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式
// 定义消息处理函数
// 获取消息处理器
dispatcher := handler.NewMessageMatchDispatcher()
bot.MessageHandler = dispatcher.AsMessageHandler()
bot.UUIDCallback = consoleQrCode // 注册登陆二维码回调
// 登录回调
bot.SyncCheckCallback = nil
reloadStorage := openwechat.NewFileHotReloadStorage("token.json")
if err := bot.HotLogin(reloadStorage, openwechat.NewRetryLoginOption()); nil != err {
panic(err)
}
// 获取当前登录的用户
self, err := bot.GetCurrentUser()
if nil != err {
panic(err)
}
go handler.KeepAlive(self)
logrus.Infof("login success %+v", *self.User)
bot.Block()
}
func consoleQrCode(uuid string) {
println("访问下面网址扫描二维码登录")
q, _ := qrcode.New("https://login.weixin.qq.com/l/"+uuid, qrcode.Medium)
fmt.Println(q.ToSmallString(false))
}