diff --git a/buttsbot.go b/buttsbot.go index 17e85eb..01aaff0 100644 --- a/buttsbot.go +++ b/buttsbot.go @@ -40,6 +40,7 @@ func main() { //Handlers Session.AddHandler(ready) + Session.AddHandler(messageCreate) //Open a connection to Discord err = Session.Open() @@ -66,3 +67,26 @@ func ready(s *discordgo.Session, event *discordgo.Ready) { s.UpdateStatus(0, "with butts!") s.ChannelMessageSend(bot_channel, "This isn't a butt...") } + +func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { + //Ignore messages by itself + if m.Author.ID == s.State.User.ID { + return + } + + //Check if the bot was mentioned + if isUserMentioned(m, s.State.User) == true { + s.ChannelMessageSend(m.ChannelID, "butt") + } +} + +//Easy way to check if a user was mentioned in a message +func isUserMentioned(m *discordgo.MessageCreate, u *discordgo.User) bool { + //mentioned := false + for _, user := range m.Mentions { + if user.ID == u.ID { + return true + } + } + return false +}