-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (32 loc) · 930 Bytes
/
main.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
package main
import (
"context"
"time"
"github.com/hduhelp/qqbot-demo/config"
"github.com/hduhelp/qqbot-demo/handler"
"github.com/hduhelp/qqbot-demo/logging"
"github.com/tencent-connect/botgo"
"github.com/tencent-connect/botgo/token"
"github.com/tencent-connect/botgo/websocket"
"go.uber.org/zap"
)
func init() {
config.Init()
logging.Init()
}
func main() {
conf := config.Bot()
token := token.BotToken(conf.AppId, conf.Token)
api := botgo.NewSandboxOpenAPI(token).WithTimeout(3 * time.Second)
handler.RegisterApi(api)
botgo.SetLogger(logging.Logger().Sugar())
ws, err := api.WS(context.Background(), nil, "")
if err != nil {
logging.Fatalf("%+v, error:%v", ws, err)
}
intent := websocket.RegisterHandlers(handler.Get())
intent |= 1 << 25 // 注册群和私聊消息
if err := botgo.NewSessionManager().Start(ws, token, &intent); err != nil {
logging.Fatal("unexpected exit", zap.Error(err))
}
}