This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
109 lines (97 loc) · 2.79 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
// FIXME: 接收用Pack,发送用Payload
import (
"encoding/base64"
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"github.com/xiyaowong/go-botoy"
)
var (
botID int
botAddress string
bot *botoy.Botoy
)
func init() {
botID, err := strconv.Atoi(os.Getenv("BotID"))
if err != nil {
fmt.Print("输入机器人QQ号:")
fmt.Scanf("%d", &botID)
}
botAddress = os.Getenv("BotAddress")
if botAddress == "" {
fmt.Print("输入机器人连接地址:")
fmt.Scanf("%s", &botAddress)
}
fmt.Println(botID, botAddress)
bot = botoy.NewBotoy(int64(botID), botAddress)
}
// 这个函数用来处理进群事件
func someoneJoin(pack botoy.GroupJoinPack) {
bot.Do(&botoy.GroupTextPayload{GroupID: pack.EventMsg.FromUin, Text: fmt.Sprintf("欢迎 <%s> 加入本群!", pack.EventData.UserName)})
}
func main() {
// 连接成功后给手机发送提示
bot.AddReceiver(func(_ botoy.ConnectedPack) {
bot.Do(&botoy.PhoneTextPayload{Text: "socketio已连接!"})
})
bot.AddReceiver(
// 复读好友发给机器人的文字消息
func(pack botoy.FriendMsgPack) {
if pack.FromUin == pack.CurrentQQ {
return
}
if pack.MsgType == botoy.TextMsgType {
bot.Do(&botoy.FriendTextPayload{ToUserID: pack.FromUin, Text: pack.Content})
}
},
// 收到群文字消息为 go 时,回复该消息,回复内容为 gogogo
func(pack botoy.GroupMsgPack) {
if pack.FromUserID == pack.CurrentQQ {
return
}
if pack.MsgType == botoy.TextMsgType && pack.Content == "go" {
bot.Do(&botoy.GroupReplyPayload{
GroupID: pack.FromGroupID,
Content: "gogogo",
RawMsgContent: pack.Content,
RawMsgSeq: pack.MsgSeq,
RawMsgTime: pack.MsgTime,
RawMsgUserID: pack.FromUserID,
})
}
},
)
// 好友撤回一条消息时,立即问他撤回了什么见不得人的东西
bot.AddReceiver(
func(pack botoy.FriendRevokePack) {
bot.Do(&botoy.FriendTextPayload{ToUserID: int64(pack.Eventmsg.Fromuin), Text: "撤回了什么见不得人的东西??"})
},
// 新成员加群事件
someoneJoin,
)
// 收到群消息为 壁纸 时 发送一张图片
bot.AddReceiver(func(pack botoy.GroupMsgPack) {
if pack.Content == "壁纸" {
bot.Do(&botoy.GroupPicPayload{GroupID: pack.FromGroupID, PicURL: "http://api.btstu.cn/sjbz/?lx=dongman"})
}
})
// 收到群消息为 base64 时 通过base64发送一张图片
bot.AddReceiver(func(pack botoy.GroupMsgPack) {
if pack.Content == "base64" {
picBytes, err := ioutil.ReadFile("./base64.jpg")
if err != nil {
log.Println(err)
return
}
picBase64 := base64.StdEncoding.EncodeToString(picBytes)
bot.Do(&botoy.GroupPicPayload{GroupID: pack.FromGroupID, PicBase64: picBase64})
}
})
/////////////////////////////////////
if err := bot.Start(); err != nil {
panic(err)
}
}