From 8d8f096d25a1c50bf5300764d50240c5508723df Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 15 Apr 2018 12:13:19 +0200 Subject: [PATCH] Added !a command to Tsundere --- bots/discord/OnMessageCreate.go | 53 ++++++++++----------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/bots/discord/OnMessageCreate.go b/bots/discord/OnMessageCreate.go index 236d9138..991a028e 100644 --- a/bots/discord/OnMessageCreate.go +++ b/bots/discord/OnMessageCreate.go @@ -3,6 +3,8 @@ package main import ( "strings" + "github.com/animenotifier/arn" + "github.com/bwmarrin/discordgo" ) @@ -34,11 +36,6 @@ func OnMessageCreate(s *discordgo.Session, msg *discordgo.MessageCreate) { return } - if strings.HasPrefix(msg.Content, "!anime ") { - s.ChannelMessageSend(msg.ChannelID, "https://notify.moe/anime/"+strings.Split(msg.Content, " ")[1]) - return - } - if strings.HasPrefix(msg.Content, "!animelist ") { s.ChannelMessageSend(msg.ChannelID, "https://notify.moe/+"+strings.Split(msg.Content, " ")[1]+"/animelist") return @@ -59,40 +56,20 @@ func OnMessageCreate(s *discordgo.Session, msg *discordgo.MessageCreate) { return } - // if strings.HasPrefix(msg.Content, "!s ") { - // term := msg.Content[len("!s "):] - // users, animes, posts, threads, tracks, characters := arn.Search(term, 3, 3, 3, 3, 3, 3) - // message := "" + if strings.HasPrefix(msg.Content, "!a ") { + term := msg.Content[len("!a "):] + animes := arn.SearchAnime(term, 3) + message := "" - // for _, user := range users { - // message += "https://notify.moe" + user.Link() + "\n" - // } + for _, anime := range animes { + message += "https://notify.moe" + anime.Link() + "\n" + } - // for _, anime := range animes { - // message += "https://notify.moe" + anime.Link() + "\n" - // } + if len(animes) == 0 { + message = "Sorry, I couldn't find anything using that term." + } - // for _, post := range posts { - // message += "https://notify.moe" + post.Link() + "\n" - // } - - // for _, thread := range threads { - // message += "https://notify.moe" + thread.Link() + "\n" - // } - - // for _, track := range tracks { - // message += "https://notify.moe" + track.Link() + "\n" - // } - - // for _, character := range characters { - // message += "https://notify.moe" + character.Link() + "\n" - // } - - // if len(users) == 0 && len(animes) == 0 && len(posts) == 0 && len(threads) == 0 && len(tracks) == 0 { - // message = "Sorry, I couldn't find anything using that term." - // } - - // s.ChannelMessageSend(msg.ChannelID, message) - // return - // } + s.ChannelMessageSend(msg.ChannelID, message) + return + } }