54 lines
1.2 KiB
Go
Raw Normal View History

2018-03-06 16:34:02 +00:00
package main
import (
2018-07-10 15:46:17 +00:00
"github.com/animenotifier/notify.moe/bots/discord/commands"
2018-03-06 16:34:02 +00:00
"github.com/bwmarrin/discordgo"
)
2018-07-10 15:46:17 +00:00
// Command represents a single bot command function signature.
type Command func(*discordgo.Session, *discordgo.MessageCreate) bool
var allCommands = []Command{
commands.AnimeList,
commands.AnimeSearch,
commands.Play,
commands.RandomQuote,
2018-07-10 16:04:58 +00:00
commands.Roles,
2018-07-10 15:46:17 +00:00
commands.Source,
2018-11-14 01:33:46 +00:00
commands.Verify,
2018-07-10 07:51:34 +00:00
}
2018-03-06 16:34:02 +00:00
// OnMessageCreate is called every time a new message is created on any channel.
func OnMessageCreate(s *discordgo.Session, msg *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself
if msg.Author.ID == s.State.User.ID {
return
}
if msg.Content == "!help" || msg.Content == "!commands" {
2018-03-06 16:34:02 +00:00
s.ChannelMessageSend(msg.ChannelID, `
**!a** [anime search term]
2018-03-06 16:34:02 +00:00
**!animelist** [username]
**!play** [status text]
**!randomquote**
2018-07-09 10:38:44 +00:00
**!source**
2018-11-14 01:33:46 +00:00
**!verify** [username]`)
2018-03-06 16:34:02 +00:00
}
// Has the bot been mentioned?
for _, user := range msg.Mentions {
if user.ID == discord.State.User.ID {
s.ChannelMessageSend(msg.ChannelID, msg.Author.Mention()+" :heart:")
return
}
}
2018-07-10 15:46:17 +00:00
// Has the user invoked a command?
for _, cmd := range allCommands {
if cmd(s, msg) {
2018-07-10 07:51:34 +00:00
return
2018-07-09 11:40:48 +00:00
}
}
2018-03-06 16:34:02 +00:00
}