-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckpoint.go
51 lines (40 loc) · 980 Bytes
/
checkpoint.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
package checkpoint
import (
"github.com/bwmarrin/discordgo"
"github.com/vidhanio/checkpoint/guild"
"github.com/vidhanio/checkpoint/student"
)
type Checkpoint struct {
session *discordgo.Session
students student.Students
guilds *guild.GuildStore
guildID string
}
func New(botToken string, guildID string, studentsFilename string, guildsPathFilename string) *Checkpoint {
s, err := discordgo.New("Bot " + botToken)
if err != nil {
panic(err)
}
c := &Checkpoint{
session: s,
students: student.MakeStudents(studentsFilename),
guilds: guild.NewGuilds(guildsPathFilename),
guildID: guildID,
}
s.AddHandler(c.handler)
return c
}
func (c *Checkpoint) Start() error {
err := c.session.Open()
if err != nil {
return err
}
_, err = c.session.ApplicationCommandBulkOverwrite(c.session.State.User.ID, c.guildID, commands)
if err != nil {
return err
}
return c.guilds.Open()
}
func (c *Checkpoint) Stop() error {
return c.session.Close()
}