-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.go
119 lines (94 loc) · 2.89 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package bot
import (
"fmt"
"math"
"strings"
"time"
"github.com/fuel-/gideon/config"
"github.com/bwmarrin/discordgo"
)
var botID string
var goBot *discordgo.Session
//Start will start our bot a runnin'
func Start() {
fmt.Println("howdy")
goBot, err := discordgo.New("Bot " + config.Token)
if err != nil {
fmt.Println(err.Error())
return
}
u, err := goBot.User("@me")
if err != nil {
fmt.Println(err.Error())
}
botID = u.ID
goBot.AddHandler(messageHandler)
err = goBot.Open()
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println("Bot is running!")
missionTimeGet()
}
func missionTimeGet() (hours, minutes int) {
loc, _ := time.LoadLocation("America/Chicago")
now := time.Now().In(loc)
fmt.Println("\nToday : ", loc, " Time : ", now)
guildMissionDay := "Saturday"
weekday := now.Weekday()
daysToAdd := 0
if weekday.String() != guildMissionDay {
weekdayInt := int(weekday)
daysToAdd = 6 - weekdayInt
}
future := now.AddDate(0, 0, daysToAdd)
year := now.Year()
month := now.Month()
day := future.Day()
fmt.Printf("current weekday is %v \n\n\n", weekday)
fmt.Printf("###############################################################\n\n\n")
futureDate := time.Date(year, month, day, 20, 00, 00, 000, loc)
fmt.Println("Future : ", loc, " Time : ", futureDate) //
fmt.Printf("###############################################################\n")
diff := futureDate.Sub(now)
hrs := int(diff.Hours())
fmt.Printf("Diffrence in Hours : %d Hours\n", hrs)
mins := int(diff.Minutes())
fmt.Printf("Diffrence in Minutes : %d Minutes\n", mins)
sec := int(diff.Seconds())
fmt.Printf("Difference in Seconds: %d Seconds\n", sec)
return hrs, mins
}
func messageHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
message := ""
if strings.HasPrefix(m.Content, config.BotPrefix) {
if m.Author.ID == botID {
return
}
if m.Content == "!ping" {
_, _ = s.ChannelMessageSend(m.ChannelID, "pong!")
} else if m.Content == "!gm" {
hrs, mins := missionTimeGet()
preMinutesLeft := mins / 60
minutesLeft := (preMinutesLeft * 60) - mins
newMinutesLeft := math.Abs(float64(minutesLeft))
if math.Signbit(float64(hrs)) {
message = fmt.Sprintf("Sorry! Guild misssions started %d and %.0f ago.", hrs, newMinutesLeft)
} else {
message = fmt.Sprintf("Guild missions start in %d hours and %.0f minutes.", hrs, newMinutesLeft)
}
_, _ = s.ChannelMessageSend(m.ChannelID, message)
} else if m.Content == "!help" {
message = "Currently my list of commands are !ping, !gm and !brad"
_, _ = s.ChannelMessageSend(m.ChannelID, message)
} else if m.Content == "!brad" {
message = "is dad."
_, _ = s.ChannelMessageSend(m.ChannelID, message)
} else if m.Content == "!goodbot" {
message = "Aww, Thank you! https://media.giphy.com/media/1gbQIeNzZxcSk/giphy.gif"
_, _ = s.ChannelMessageSend(m.ChannelID, message)
}
fmt.Println(m.Content)
}
}