-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.go
66 lines (50 loc) · 1.53 KB
/
bot.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
package alasbot
import (
"fmt"
)
type Bot struct {
Game Game
Chat Chat
BloodmoonOffset int
}
type Game interface {
PlayerCount() (int, int, error)
GameTime() (int, int, int, int, error)
}
type Chat interface {
OnMessage(func(author, message string) string)
}
func (bot Bot) Start() {
bot.Chat.OnMessage(func(author, message string) string {
if message == "!server" {
count, max, err := bot.Game.PlayerCount()
if err != nil {
return "Sorry, could not get player count: " + err.Error()
}
days, hours, minutes, bloodMoonFrequency, err := bot.Game.GameTime()
if err != nil {
return "Sorry, could not get server time: " + err.Error()
}
playersMessage := fmt.Sprintf("Server is online, %v/%v players.", count, max)
timeMessage := fmt.Sprintf("Its day %v, the time is %02d:%02d.", days, hours, minutes)
bloodMoonMessage := BloodMoonMessage(days, hours, minutes, bloodMoonFrequency, bot.BloodmoonOffset)
return fmt.Sprint(playersMessage, " ", timeMessage, " ", bloodMoonMessage)
}
return ""
})
}
func BloodMoonMessage(days, hours, minutes, bloodMoonFrequency, offset int) string {
msg := fmt.Sprintf("The next bloodmoon will be on day %v.", (((days-offset)/bloodMoonFrequency)+1)*bloodMoonFrequency+offset)
if ((days - offset) % bloodMoonFrequency) == 0 {
msg = "The next bloodmoon will be today."
if hours >= 22 {
msg = "A bloodmoon is active!"
}
}
if ((days - offset) % bloodMoonFrequency) == 1 {
if hours < 4 {
msg = "A bloodmoon is active!"
}
}
return msg
}