37 lines
735 B
Go
Raw Normal View History

2018-07-10 15:46:17 +00:00
package commands
import (
"strings"
"github.com/akyoto/color"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn/search"
2018-07-10 15:46:17 +00:00
"github.com/bwmarrin/discordgo"
)
// AnimeSearch shows the link for the anime list of a user.
func AnimeSearch(s *discordgo.Session, msg *discordgo.MessageCreate) bool {
2018-07-10 16:04:58 +00:00
if !strings.HasPrefix(msg.Content, "!a ") {
2018-07-10 15:46:17 +00:00
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."
}
_, err := s.ChannelMessageSend(msg.ChannelID, message)
if err != nil {
color.Red(err.Error())
}
2018-07-10 15:46:17 +00:00
return true
}