-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
114 lines (96 loc) · 2.91 KB
/
handler.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
package diswordle
import (
"regexp"
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog/log"
"github.com/vidhanio/wordle"
)
func (wb *WordleBot) setGuilds(s *discordgo.Session, r *discordgo.Ready) {
for _, g := range r.Guilds {
wb.wordles[g.ID] = make(map[string]*wordleGame)
}
}
func (wb *WordleBot) createGuild(s *discordgo.Session, g *discordgo.GuildCreate) {
_, ok := wb.wordles[g.ID]
if !ok {
wb.wordles[g.ID] = make(map[string]*wordleGame)
}
}
func (wb *WordleBot) setEmojis(s *discordgo.Session, r *discordgo.Ready) {
notGuessedRegex := regexp.MustCompile(`([a-z])_grey`)
wrongRegex := regexp.MustCompile(`([a-z])_black`)
wrongPositionRegex := regexp.MustCompile(`([a-z])_yellow`)
correctRegex := regexp.MustCompile(`([a-z])_green`)
wb.emojiMap = make(map[wordle.GuessResult][26]*discordgo.Emoji)
notGuessedEmojis := [26]*discordgo.Emoji{}
wrongEmojis := [26]*discordgo.Emoji{}
wrongPositionEmojis := [26]*discordgo.Emoji{}
correctEmojis := [26]*discordgo.Emoji{}
for _, g := range r.Guilds {
if g.ID == wb.emojiGuilds[wordle.GuessResultNotGuessed] {
emojis, err := s.GuildEmojis(g.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get guild emojis")
}
for _, e := range emojis {
match := notGuessedRegex.FindStringSubmatch(e.Name)
if match != nil {
notGuessedEmojis[match[1][0]-'a'] = e
}
}
}
if g.ID == wb.emojiGuilds[wordle.GuessResultCorrect] {
emojis, err := s.GuildEmojis(g.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get guild emojis")
}
for _, e := range emojis {
match := correctRegex.FindStringSubmatch(e.Name)
if match != nil {
correctEmojis[match[1][0]-'a'] = e
}
}
}
if g.ID == wb.emojiGuilds[wordle.GuessResultWrongPosition] {
emojis, err := s.GuildEmojis(g.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get guild emojis")
}
for _, e := range emojis {
match := wrongPositionRegex.FindStringSubmatch(e.Name)
if match != nil {
wrongPositionEmojis[match[1][0]-'a'] = e
}
}
}
if g.ID == wb.emojiGuilds[wordle.GuessResultWrong] {
emojis, err := s.GuildEmojis(g.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get guild emojis")
}
for _, e := range emojis {
match := wrongRegex.FindStringSubmatch(e.Name)
if match != nil {
wrongEmojis[match[1][0]-'a'] = e
}
}
}
if g.ID == wb.miscEmojiGuild {
emojis, err := s.GuildEmojis(wb.miscEmojiGuild)
if err != nil {
log.Error().Err(err).Msg("Failed to get guild emojis")
}
for _, e := range emojis {
if e.Name == "blank" {
wb.blankEmoji = e
} else if e.Name == "empty" {
wb.emptyEmoji = e
}
}
}
}
wb.emojiMap[wordle.GuessResultNotGuessed] = notGuessedEmojis
wb.emojiMap[wordle.GuessResultWrong] = wrongEmojis
wb.emojiMap[wordle.GuessResultWrongPosition] = wrongPositionEmojis
wb.emojiMap[wordle.GuessResultCorrect] = correctEmojis
}