Added random quote display to Discord bot

This commit is contained in:
Eduard Urbach 2018-07-02 16:19:07 +09:00
parent 26a3d141ac
commit b857b21a2a

View File

@ -1,8 +1,11 @@
package main package main
import ( import (
"math/rand"
"strings" "strings"
"github.com/animenotifier/arn"
"github.com/animenotifier/arn/search" "github.com/animenotifier/arn/search"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
@ -14,12 +17,13 @@ func OnMessageCreate(s *discordgo.Session, msg *discordgo.MessageCreate) {
return return
} }
if msg.Content == "!commands" { if msg.Content == "!help" || msg.Content == "!commands" {
s.ChannelMessageSend(msg.ChannelID, ` s.ChannelMessageSend(msg.ChannelID, `
**!user** [username] **!a** [anime search term]
**!anime** [id]
**!animelist** [username] **!animelist** [username]
**!tag** [forum tag]`) **!play** [status text]
**!randomquote**
**!source**`)
} }
// Has the bot been mentioned? // Has the bot been mentioned?
@ -30,31 +34,7 @@ func OnMessageCreate(s *discordgo.Session, msg *discordgo.MessageCreate) {
} }
} }
if strings.HasPrefix(msg.Content, "!user ") { // Anime search
s.ChannelMessageSend(msg.ChannelID, "https://notify.moe/+"+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
}
if strings.HasPrefix(msg.Content, "!tag ") {
s.ChannelMessageSend(msg.ChannelID, "https://notify.moe/forum/"+strings.ToLower(strings.Split(msg.Content, " ")[1]))
return
}
if strings.HasPrefix(msg.Content, "!play ") {
s.UpdateStatus(0, msg.Content[len("!play "):])
return
}
if msg.Content == "!source" {
s.ChannelMessageSend(msg.ChannelID, msg.Author.Mention()+" B-baaaaaaaka! Y..you...you want to...TOUCH MY CODE?!\n\nhttps://github.com/animenotifier/notify.moe/tree/go/bots/discord")
return
}
if strings.HasPrefix(msg.Content, "!a ") { if strings.HasPrefix(msg.Content, "!a ") {
term := msg.Content[len("!a "):] term := msg.Content[len("!a "):]
animes := search.Anime(term, 3) animes := search.Anime(term, 3)
@ -71,4 +51,30 @@ func OnMessageCreate(s *discordgo.Session, msg *discordgo.MessageCreate) {
s.ChannelMessageSend(msg.ChannelID, message) s.ChannelMessageSend(msg.ChannelID, message)
return return
} }
// Anime list of user
if strings.HasPrefix(msg.Content, "!animelist ") {
s.ChannelMessageSend(msg.ChannelID, "https://notify.moe/+"+strings.Split(msg.Content, " ")[1]+"/animelist")
return
}
// Play status
if strings.HasPrefix(msg.Content, "!play ") {
s.UpdateStatus(0, msg.Content[len("!play "):])
return
}
// Random quote
if msg.Content == "!randomquote" {
allQuotes := arn.AllQuotes()
quote := allQuotes[rand.Intn(len(allQuotes))]
s.ChannelMessageSend(msg.ChannelID, "https://notify.moe"+quote.Link())
return
}
// GitHub source of the bot
if msg.Content == "!source" {
s.ChannelMessageSend(msg.ChannelID, msg.Author.Mention()+" B-baaaaaaaka! Y..you...you want to...TOUCH MY CODE?!\n\nhttps://github.com/animenotifier/notify.moe/tree/go/bots/discord")
return
}
} }