Added new bot commands
This commit is contained in:
parent
3a3867cc21
commit
173a3c996d
@ -13,6 +13,7 @@ type Command func(*discordgo.Session, *discordgo.MessageCreate) bool
|
||||
var allCommands = []Command{
|
||||
commands.AnimeList,
|
||||
commands.AnimeSearch,
|
||||
commands.Did,
|
||||
commands.Play,
|
||||
commands.RandomQuote,
|
||||
commands.Roles,
|
||||
|
81
bots/discord/commands/Did.go
Normal file
81
bots/discord/commands/Did.go
Normal file
@ -0,0 +1,81 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/akyoto/color"
|
||||
"github.com/animenotifier/notify.moe/arn"
|
||||
"github.com/animenotifier/notify.moe/arn/search"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var (
|
||||
watchedAnimeRegex = regexp.MustCompile(`did (.*?) watch (.*?)\?`)
|
||||
)
|
||||
|
||||
// Did answers some questions with the pattern "Did ...?".
|
||||
func Did(s *discordgo.Session, msg *discordgo.MessageCreate) bool {
|
||||
if !strings.HasPrefix(msg.Content, "!did ") {
|
||||
return false
|
||||
}
|
||||
|
||||
matches := watchedAnimeRegex.FindStringSubmatch(msg.Content)
|
||||
|
||||
if len(matches) < 3 {
|
||||
_, err := s.ChannelMessageSend(msg.ChannelID, "I don't understand that question")
|
||||
|
||||
if err != nil {
|
||||
color.Red(err.Error())
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
userName := matches[1]
|
||||
animeName := matches[2]
|
||||
|
||||
user, err := arn.GetUser(userName)
|
||||
|
||||
if err != nil {
|
||||
_, err := s.ChannelMessageSend(msg.ChannelID, "User not found")
|
||||
|
||||
if err != nil {
|
||||
color.Red(err.Error())
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
results := search.Anime(animeName, 1)
|
||||
|
||||
if len(results) == 0 {
|
||||
_, err := s.ChannelMessageSend(msg.ChannelID, "Anime not found")
|
||||
|
||||
if err != nil {
|
||||
color.Red(err.Error())
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
anime := results[0]
|
||||
animeList := user.AnimeList()
|
||||
|
||||
if animeList.Contains(anime.ID) {
|
||||
_, err := s.ChannelMessageSend(msg.ChannelID, fmt.Sprintf("Yes, %s has watched %s.", user.Nick, anime.Title.Canonical))
|
||||
|
||||
if err != nil {
|
||||
color.Red(err.Error())
|
||||
}
|
||||
} else {
|
||||
_, err := s.ChannelMessageSend(msg.ChannelID, fmt.Sprintf("No, %s hasn't watched %s.", user.Nick, anime.Title.Canonical))
|
||||
|
||||
if err != nil {
|
||||
color.Red(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue
Block a user