pepebot/discord/discord.go

89 lines
2.6 KiB
Go
Raw Normal View History

2021-05-18 12:11:30 +02:00
package main
import (
"strings"
"github.com/bwmarrin/discordgo"
)
func (app *application) messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.Bot {
return
}
2021-05-31 11:21:30 +02:00
app.limiter.LogInteraction(m.Author.ID, "messagecreate")
2021-05-18 12:11:30 +02:00
2021-05-31 10:58:16 +02:00
/* Check if the user is even allowed by the rate limiter */
err := app.limiter.CheckAllowed(m.Author.ID)
if err != nil {
/* normally don't send, but now do for debug purposes. This is the admin bot channel */
2021-05-31 11:29:49 +02:00
//app.unknownError(err, s, true, "815952128106430514")
app.infoLog.Printf("Rate limit exceeded by used %s", m.Author.Username)
channel, err := s.UserChannelCreate(m.Author.ID)
if err != nil {
app.errorLog.Printf("Cannot create user PM channel to inform about rate limit, %s", err.Error())
return
}
s.ChannelMessageSend(channel.ID, "You exceeded the rate limit for the server, please stop spamming")
2021-05-31 10:58:16 +02:00
return
}
/* Checking if the message starts with the trigger specified in application struct
2021-05-18 12:11:30 +02:00
if it does then we start the switch statement to trigger the appropriate function
if it does not then we check if it contains a triggerword from the database */
if strings.HasPrefix(m.Content, app.trigger) {
splitCommand := strings.Split(strings.TrimSpace(m.Content), " ")
/* If the whole message on it's own is just "!pepe" aka the triggerword, then send a pepe and stop */
if strings.TrimSpace(m.Content) == app.trigger {
app.sendPepe(s, m)
return
}
/* This switches on the first word in the message
it could be anything starting with !pepe */
if len(splitCommand) > 1 {
switch splitCommand[1] {
/* --- Funny commands --- */
case "cringe":
app.sendCringe(s, m)
case "gif":
app.sendNigelGif(s, m)
2021-05-31 14:31:13 +02:00
case "monday":
app.sendMonday(s, m)
2021-05-18 12:37:26 +02:00
case "tuesday":
app.sendTuesday(s, m)
2021-05-18 12:54:04 +02:00
case "wednesday":
app.sendWednesday(s, m)
2021-12-17 15:09:23 +01:00
case "friday":
app.sendFriday(s, m)
2021-05-18 12:56:16 +02:00
case "github", "source":
app.sendGithub(s, m)
2021-09-23 14:35:43 +02:00
case "peski", "rotterdam":
app.sendPeski(s, m)
2021-12-17 15:38:34 +01:00
case "proper", "based":
app.sendProper(s, m)
2021-05-18 12:11:30 +02:00
/* --- Bot commands for words --- */
2021-05-25 12:19:52 +02:00
case "spam":
2021-05-25 10:50:24 +02:00
app.sendManyPepes(s, m, splitCommand)
2021-05-25 11:15:41 +02:00
case "stop":
app.stopRequest(s, m)
2021-05-18 12:11:30 +02:00
/* --- Bot commands, but only admins --- */
case "addword":
app.addWord(s, m, splitCommand)
case "removeword":
app.removeWord(s, m, splitCommand)
case "addadmin":
app.addAdmin(s, m, splitCommand)
case "removeadmin":
app.removeAdmin(s, m, splitCommand)
2021-09-23 13:38:30 +02:00
case "reload":
app.reloadPepeList(s, m)
2021-05-18 12:11:30 +02:00
}
2021-05-31 10:58:16 +02:00
2021-05-18 12:11:30 +02:00
}
} else {
/* If the trigger wasn't the prefix of the message, we need to check all the words for a trigger */
app.findTrigger(s, m)
}
2021-05-31 10:58:16 +02:00
}