Refactor bot command invocation

This commit is contained in:
2018-07-11 00:46:17 +09:00
parent 957de3856b
commit 009449316e
7 changed files with 183 additions and 100 deletions

View File

@ -0,0 +1,30 @@
package commands
import (
"strings"
"github.com/animenotifier/arn/search"
"github.com/bwmarrin/discordgo"
)
// AnimeSearch shows the link for the anime list of a user.
func AnimeSearch(s *discordgo.Session, msg *discordgo.MessageCreate) bool {
if strings.HasPrefix(msg.Content, "!a ") {
return false
}
term := msg.Content[len("!a "):]
animes := search.Anime(term, 3)
message := ""
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."
}
s.ChannelMessageSend(msg.ChannelID, message)
return true
}