forked from johansundell/cocbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreportdaily.go
More file actions
60 lines (55 loc) · 1.11 KB
/
reportdaily.go
File metadata and controls
60 lines (55 loc) · 1.11 KB
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
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/bwmarrin/discordgo"
)
func getTime() time.Time {
now := time.Now()
t := time.Date(now.Year(), now.Month(), now.Day(), 23, 58, 0, 0, time.Local)
return t
}
func getDuration() time.Duration {
t := getTime()
return t.Sub(time.Now())
}
func test(s *discordgo.Session) {
//now := time.Now()
t := getTime()
//t = t.Add(time.Minute * time.Duration(2))
//fmt.Println(t)
//return
d := t.Sub(time.Now())
//fmt.Println(d)
//ticker := time.NewTicker(1 * time.Minute)
ticker := time.NewTimer(d)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
fmt.Println("ticker hit")
//lockMap.RLock()
ctx := context.Background()
msg, err := botFuncs[keyTopDonators](ctx, "!top donators today")
//lockMap.RUnlock()
if err != nil {
log.Println(err)
} else {
fmt.Println(msg)
sendMessage(s, msg, true)
}
t = getTime()
t = t.Add(time.Hour * time.Duration(24))
d = t.Sub(time.Now())
ticker.Reset(d)
fmt.Println("ran", d)
case <-quit:
ticker.Stop()
return
}
}
}()
}