-
Notifications
You must be signed in to change notification settings - Fork 0
/
greeting.go
50 lines (47 loc) · 1.17 KB
/
greeting.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
package main
import (
"github.com/sirupsen/logrus"
"strconv"
"time"
)
func DailyGreetings() {
t := time.NewTimer(SetTime(7, 0, 0))
defer t.Stop()
for {
select {
case <-t.C:
t.Reset(time.Hour * 24)
SendGreetings()
}
}
}
func SendGreetings() {
friendInfos, err := GetFriendList()
if err != nil {
logrus.Error("[DailyGreetings]get friend list fail: " + err.Error())
}
groupInfos, err := GetGroupList()
if err != nil {
logrus.Error("[DailyGreetings]get group list fail: " + err.Error())
}
sender := SendMsgData{
Message: []Message{GlobalConfig.Greeting.GreetingMessage},
AutoEscape: false,
}
for _, friendInfo := range friendInfos {
sender.MessageType = "private"
sender.UserId = strconv.FormatInt(friendInfo.UserId, 10)
err := sender.Send()
if err != nil {
logrus.Error("[DailyGreetings]send greeting to friend " + sender.UserId + " fail: " + err.Error())
}
}
for _, groupInfo := range groupInfos {
sender.MessageType = "group"
sender.GroupId = strconv.FormatInt(groupInfo.GroupId, 10)
err := sender.Send()
if err != nil {
logrus.Error("[DailyGreetings]send greeting to group " + sender.UserId + " fail: " + err.Error())
}
}
}