diff options
| author | Bobby <[email protected]> | 2024-11-16 20:43:41 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-11-16 20:43:41 -0500 |
| commit | b2910b9252850f1c413c7a153fac4c152900964a (patch) | |
| tree | 9ca802b764267b83c9dbd5a45ab24f225fccb78e /handlers/messageHandlers | |
| parent | 2e79b5aa8cfe8433bcd9d1d415826056fea8fcb2 (diff) | |
| download | yuzaki-b2910b9252850f1c413c7a153fac4c152900964a.tar.xz yuzaki-b2910b9252850f1c413c7a153fac4c152900964a.zip | |
added poketwo handler
Diffstat (limited to 'handlers/messageHandlers')
| -rw-r--r-- | handlers/messageHandlers/poketwoHandler.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/handlers/messageHandlers/poketwoHandler.go b/handlers/messageHandlers/poketwoHandler.go new file mode 100644 index 0000000..f124e02 --- /dev/null +++ b/handlers/messageHandlers/poketwoHandler.go @@ -0,0 +1,86 @@ +package messagehandlers + +import ( + "fmt" + "strings" + "time" + + "github.com/bwmarrin/discordgo" +) + +var ( + poketwoID = "716390085896962058" + poketwoChannels = []string{"1307335103508254844", "1307335132046168074"} +) + +func PoketwoHandler(s *discordgo.Session, m *discordgo.MessageCreate) { + isAllowed := isAllowedChannel(m.ChannelID) + + if m.Author.ID == poketwoID { + if !isAllowed { + s.ChannelMessageDelete(m.ChannelID, m.ID) + } + return + } + + isCommand := strings.HasPrefix(strings.ToLower(m.Content), "p!") || + (len(m.Mentions) > 0 && m.Mentions[0].ID == poketwoID) + + if isCommand && !isAllowed { + channel, err := s.Channel(m.ChannelID) + if err != nil { + return + } + + fmt.Printf("%s#%s sent a Poketwo command in #%s - deleting\n", + m.Author.Username, m.Author.Discriminator, channel.Name) + + go func() { + time.Sleep(1 * time.Second) + s.ChannelMessageDelete(m.ChannelID, m.ID) + }() + + var channelMentions string + for i, channelID := range poketwoChannels { + if i == len(poketwoChannels)-1 && i > 0 { + channelMentions += "or " + } + channelMentions += fmt.Sprintf("<#%s>", channelID) + if i < len(poketwoChannels)-2 { + channelMentions += ", " + } + } + + _, err = s.ChannelMessageSend(m.ChannelID, + fmt.Sprintf("<@%s>, please use %s for Pokétwo commands. If you need roles, visit <id:customize> to get them.", + m.Author.ID, channelMentions)) + + if err != nil { + return + } + + go func() { + time.Sleep(1 * time.Second) + messages, err := s.ChannelMessages(m.ChannelID, 5, "", "", "") + if err != nil { + return + } + + for _, msg := range messages { + if msg.Author.ID == poketwoID { + s.ChannelMessageDelete(m.ChannelID, msg.ID) + break + } + } + }() + } +} + +func isAllowedChannel(channelID string) bool { + for _, channel := range poketwoChannels { + if channelID == channel { + return true + } + } + return false +} |
