-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.go
49 lines (38 loc) · 1.12 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
package bot
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/jonathroth/temp-chat/state"
)
// TempChannelBot contains all the handlers to discord events for the bot to operate.
type TempChannelBot struct {
// Whether to parse commands given by other bots.
// Used for running the tests
AllowBots bool
store state.ServerStore
botUserID state.DiscordID
tempChannels *TempChannelList
commands map[string]*Command
}
// NewTempChannelBot initializes a new instance of TempChannelBot.
func NewTempChannelBot(session *discordgo.Session, store state.ServerStore) (*TempChannelBot, error) {
user, err := session.User("@me")
if err != nil {
return nil, err
}
userID, err := state.ParseDiscordID(user.ID)
if err != nil {
return nil, fmt.Errorf("Failed parsing self user ID: %v", err)
}
bot := &TempChannelBot{
store: store,
botUserID: userID,
tempChannels: NewTempChannelList(session),
}
bot.commands = bot.initCommands()
return bot, nil
}
// CleanChannels deletes all the temp channels created by the bot.
func (b *TempChannelBot) CleanChannels() {
b.tempChannels.DeleteAllChannels()
}