-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
81 lines (73 loc) · 1.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
package main
import (
"fmt"
"math"
"time"
"github.com/hugolgst/rich-go/client"
)
func connect() {
for {
err := client.Login("509851616216875019")
if err != nil {
fmt.Printf("[%s] %s\n", time.Now().Format(time.RFC3339), err)
fmt.Printf("[%s] Connection failed, retrying in 30 seconds\n", time.Now().Format(time.RFC3339))
time.Sleep(30 * time.Second)
} else {
setActivity()
for range time.Tick(time.Hour) {
go setActivity()
}
break
}
}
}
func setActivity() {
now := time.Now()
t := now.Format(time.RFC3339)
format := "2006-01-02T15:04:05"
year := now.Year()
if now.Month() == 12 && now.Day() > 25 {
year++
}
christmas, err := time.Parse(format, fmt.Sprintf("%d-12-25T00:00:00", year))
if err != nil {
panic(err)
}
diff := christmas.Unix() - now.Unix()
sleeps := int64(math.Ceil(float64(diff) / 60 / 60 / 24))
var details string
if sleeps > 1 {
details = fmt.Sprintf("%d sleeps left", sleeps)
} else {
details = fmt.Sprintf("%d sleep left", sleeps)
}
state := "until Christmas"
if now.Month() == 12 && now.Day() == 25 {
details = "It's Christmas Day!"
state = "Merry Christmas!"
}
err = client.SetActivity(client.Activity{
State: state,
Details: details,
LargeImage: "santa",
Buttons: []*client.Button{
{
Label: "Watch the live countdown",
Url: "https://christmascountdown.live/?utm_source=rpc&utm_medium=button&utm_campaign=website",
},
{
Label: "Add the bot",
Url: "https://christmascountdown.live/discord?utm_source=rpc&utm_medium=button&utm_campaign=bot",
},
},
})
if err != nil {
fmt.Printf("[%s] %s\n", time.Now().Format(time.RFC3339), err)
fmt.Printf("[%s] Failed to update activity\n", t)
} else {
fmt.Printf("[%s] Updated activity (%d sleeps left)\n", t, sleeps)
}
}
func main() {
connect()
}