-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
78 lines (68 loc) · 2.11 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
package main
import (
"bestrui/wechatpush/mail"
"bestrui/wechatpush/openwechat"
"fmt"
"strings"
)
func main() {
bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式
// 创建热存储容器对象
reloadStorage := openwechat.NewFileHotReloadStorage("/app/data/storage.json")
defer reloadStorage.Close()
// 登录
if err := bot.HotLogin(reloadStorage); err != nil {
fmt.Println("热登陆失败,尝试免扫码登录")
bot.PushLogin(reloadStorage, openwechat.NewRetryLoginOption())
}
fmt.Println("登陆成功")
bot.MessageHandler = func(msg *openwechat.Message) {
if msg.IsSendBySelf() { //自己发送的消息
//跳过
return
} else if msg.IsSendByFriend() { //好友发送的消息
friendSender, err := msg.Sender()
if err != nil {
fmt.Println(err)
return
}
friendSenderName := friendSender.RemarkName
if len(friendSender.RemarkName) == 0 {
friendSenderName = friendSender.NickName
}
if msg.IsText() {
fmt.Println(friendSenderName, ":", msg.Content)
mail.SendEmail(friendSenderName, msg.Content)
} else if msg.IsPicture() {
fmt.Println(friendSenderName, ":", "[图片]")
mail.SendEmail(friendSenderName, "[图片]")
} else if msg.IsVoice() {
fmt.Println(friendSenderName, ":", "[语音]")
mail.SendEmail(friendSenderName, "[语音]")
} else if msg.IsVideo() {
fmt.Println(friendSenderName, ":", "[视频]")
mail.SendEmail(friendSenderName, "[视频]")
} else if msg.IsEmoticon() {
fmt.Println(friendSenderName, ":", "[动画表情]")
mail.SendEmail(friendSenderName, "[动画表情]")
} else {
fmt.Println(friendSenderName, ":", "[未知类型消息]")
mail.SendEmail(friendSenderName, "[未知类型消息]")
}
} else { //群聊发送的消息
groupSender, err := msg.SenderInGroup()
if err != nil {
fmt.Println(err)
return
}
if msg.IsText() {
//群聊中只接受 @所有人 消息
if strings.Contains(msg.Content, "@所有人") {
fmt.Println(groupSender.NickName, ":", msg.Content)
mail.SendEmail(groupSender.NickName, msg.Content)
}
}
}
}
bot.Block()
}