-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (41 loc) · 947 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
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
"github.com/wjunlu/opensource-bot/record"
"github.com/robfig/cron/v3"
"github.com/wjunlu/opensource-bot/login"
msg "github.com/wjunlu/opensource-bot/message"
group "github.com/wjunlu/opensource-bot/group"
)
func main() {
// 创建聊天记录存储目录
err := os.MkdirAll(record.ROOT_DOR, 0755)
if err != nil {
fmt.Println(err)
return
}
// 登录微信账户
bot := login.WechatLogin()
if bot == nil {
return
}
// 获取登陆的用户
self := login.GetLoginUser(bot)
// 注册消息处理函数
msg.HandleAllMessages(bot, self)
// 获取所有好友
group.GetAllFriends(self)
// 启动定时任务
RunPeriodicTasks()
// 阻塞主goroutine, 直到发生异常或者用户主动退出
bot.Block()
}
func RunPeriodicTasks() {
c := cron.New()
c.AddFunc("@every 24h", func() {
// 定时清空每天的聊天缓存
group.FriendsInChat = map[string]string{}
})
c.Start()
}