-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.go
73 lines (58 loc) · 1.77 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
package diswordle
import (
"os"
"github.com/bwmarrin/discordgo"
"github.com/vidhanio/wordle"
)
type WordleBot struct {
wordles map[string]map[string]*wordleGame
guildWordles map[string]*guildWordleGame
session *discordgo.Session
dictionary []string
common []string
guessesAllowed int
guildGuessesAllowed int
emojiGuilds map[wordle.GuessResult]string
miscEmojiGuild string
emojiMap map[wordle.GuessResult][26]*discordgo.Emoji
blankEmoji *discordgo.Emoji
emptyEmoji *discordgo.Emoji
}
func New(dictionary, common []string, guessesAllowed, guildGuessesAllowed int, botToken string, emojiGuilds map[wordle.GuessResult]string, miscEmojiGuild string) (*WordleBot, error) {
session, err := discordgo.New("Bot " + botToken)
if err != nil {
return nil, err
}
wb := &WordleBot{
wordles: make(map[string]map[string]*wordleGame),
guildWordles: make(map[string]*guildWordleGame),
session: session,
dictionary: dictionary,
common: common,
guessesAllowed: guessesAllowed,
guildGuessesAllowed: guildGuessesAllowed,
miscEmojiGuild: miscEmojiGuild,
emojiGuilds: emojiGuilds,
}
wb.session.AddHandler(wb.setEmojis)
wb.session.AddHandler(wb.setGuilds)
wb.session.AddHandler(wb.createGuild)
wb.session.AddHandler(wb.handleWordle)
wb.session.AddHandler(wb.handleGuildWordle)
return wb, nil
}
func (wb *WordleBot) Start() error {
err := wb.session.Open()
if err != nil {
return err
}
_, err = wb.session.ApplicationCommandBulkOverwrite(
wb.session.State.User.ID,
os.Getenv("DISCORD_GUILD_ID"),
append(wordleApplicationCommands, guildWordleApplicationCommands...),
)
return err
}
func (wb *WordleBot) Stop() error {
return wb.session.Close()
}