-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
109 lines (85 loc) · 1.97 KB
/
main.go
File metadata and controls
109 lines (85 loc) · 1.97 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
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
package main
import (
"./Utility"
"fmt"
"github.com/bwmarrin/discordgo"
"time"
)
var index int
var token string
var channels []string
var words [][2]string
func main() {
token, index = Utility.ReadJson()
words = Utility.GetCsv()
fmt.Println("csv length",len(words))
fmt.Println(token ," ", index)
dg, err := discordgo.New("Bot " + token)
if err != nil {
fmt.Println("error creating Discord session,", err)
return
}
dg.AddHandler(messageCreate)
dg.AddHandler(guildCreate)
dg.AddHandler(guildDelete)
err = dg.Open()
if err != nil {
fmt.Println("error opening connection,", err)
return
}
// Wait here until CTRL-C or other term signal is received.
fmt.Println("Bot is now running.")
waitForTime(dg)
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.Bot {
return;
}
if m.Content == "++play" {
sendWords(s)
}
return
//if Utility.StartsWith(m.Content,"++") {
//}
}
func guildCreate(s *discordgo.Session, g *discordgo.GuildCreate) {
channels = append(channels,g.SystemChannelID)
}
func guildDelete(s *discordgo.Session, g *discordgo.GuildDelete) {
channels = Utility.Remove(channels,Utility.GetIndex(g.SystemChannelID,channels))
}
func waitForTime( s *discordgo.Session) {
for {
time.Sleep(time.Minute)
if time.Now().Hour() == 8 && time.Now().Minute() == 0 {
sendWords(s)
time.Sleep(time.Minute + time.Second)
}
}
}
func sendWords(s *discordgo.Session) {
if len(words) == 0 {
for x := 0; x< len(channels);x++ {
_, err := s.ChannelMessageSend(channels[x], "the word list is empty lol")
if err != nil {
panic(err)
}
}
}
if index >= len(words) {
index = 0
fmt.Println("index has passed words length")
}
for x := 0; x < len(channels); x++ {
_, err := s.ChannelMessageSend(channels[x], words[index][0])
if err != nil {
panic(err)
}
_, err = s.ChannelMessageSend(channels[x],words[index][1])
if err != nil {
panic(err)
}
}
index += 1
Utility.UpdateIndex(index,token)
}