This commit is contained in:
DutchEllie 2021-06-03 17:07:33 +02:00
parent eff943a715
commit a8128b120a
3 changed files with 28 additions and 20 deletions

View File

@ -1,8 +1,6 @@
package main package main
import ( import (
"strings"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
@ -18,12 +16,12 @@ func (app *application) messageCreate(s *discordgo.Session, m *discordgo.Message
return return
} */ } */
app.limiter.LogInteraction(m.Author.ID, "messagecreate") //app.limiter.LogInteraction(m.Author.ID, "messagecreate")
/* Check if the user is even allowed by the rate limiter */ /* Check if the user is even allowed by the rate limiter */
err := app.limiter.CheckAllowed(m.Author.ID) /* err := app.limiter.CheckAllowed(m.Author.ID)
if err != nil { if err != nil {
/* normally don't send, but now do for debug purposes. This is the admin bot channel */ /* normally don't send, but now do for debug purposes. This is the admin bot channel *
//app.unknownError(err, s, true, "815952128106430514") //app.unknownError(err, s, true, "815952128106430514")
app.infoLog.Printf("Rate limit exceeded by used %s", m.Author.Username) app.infoLog.Printf("Rate limit exceeded by used %s", m.Author.Username)
channel, err := s.UserChannelCreate(m.Author.ID) channel, err := s.UserChannelCreate(m.Author.ID)
@ -33,24 +31,24 @@ func (app *application) messageCreate(s *discordgo.Session, m *discordgo.Message
} }
s.ChannelMessageSend(channel.ID, "You exceeded the rate limit for the server, please stop spamming") s.ChannelMessageSend(channel.ID, "You exceeded the rate limit for the server, please stop spamming")
return return
} } */
/* Checking if the message starts with the trigger specified in application struct /* Checking if the message starts with the trigger specified in application struct
if it does then we start the switch statement to trigger the appropriate function 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 it does not then we check if it contains a triggerword from the database */
if strings.HasPrefix(m.Content, app.trigger) { /* if strings.HasPrefix(m.Content, app.trigger) {
splitCommand := strings.Split(strings.TrimSpace(m.Content), " ") 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 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 { if strings.TrimSpace(m.Content) == app.trigger {
app.sendPepe(s, m) app.sendPepe(s, m)
return return
} }
/* This switches on the first word in the message /* This switches on the first word in the message
it could be anything starting with !pepe */ it could be anything starting with !pepe *
if len(splitCommand) > 1 { if len(splitCommand) > 1 {
switch splitCommand[1] { switch splitCommand[1] {
/* --- Funny commands --- */ /* --- Funny commands --- *
case "cringe": case "cringe":
app.sendCringe(s, m) app.sendCringe(s, m)
case "gif": case "gif":
@ -61,12 +59,12 @@ func (app *application) messageCreate(s *discordgo.Session, m *discordgo.Message
app.sendWednesday(s, m) app.sendWednesday(s, m)
case "github", "source": case "github", "source":
app.sendGithub(s, m) app.sendGithub(s, m)
/* --- Bot commands for words --- */ /* --- Bot commands for words --- *
case "spam": case "spam":
app.sendManyPepes(s, m, splitCommand) app.sendManyPepes(s, m, splitCommand)
case "stop": case "stop":
app.stopRequest(s, m) app.stopRequest(s, m)
/* --- Bot commands, but only admins --- */ /* --- Bot commands, but only admins --- *
case "addword": case "addword":
app.addWord(s, m, splitCommand) app.addWord(s, m, splitCommand)
case "removeword": case "removeword":
@ -79,8 +77,8 @@ func (app *application) messageCreate(s *discordgo.Session, m *discordgo.Message
} }
} else { } else {
/* If the trigger wasn't the prefix of the message, we need to check all the words for a trigger */ /* If the trigger wasn't the prefix of the message, we need to check all the words for a trigger
app.findTrigger(s, m) app.findTrigger(s, m)
} } */
} }

View File

@ -5,7 +5,3 @@ import "github.com/bwmarrin/discordgo"
func newCringe(s *discordgo.Session, m *discordgo.MessageCreate) { func newCringe(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, "this is a test message right from the new command system!") s.ChannelMessageSend(m.ChannelID, "this is a test message right from the new command system!")
} }
func newSendPepe(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, "cmd not yet working, but this needed to be registered otherwise the code would break")
}

View File

@ -63,7 +63,7 @@ func main() {
} }
mux := NewCommandMux() mux := NewCommandMux()
mux.prefix = "!newpepe" mux.prefix = "!pepe"
app := &application{ app := &application{
infoLog: infoLog, infoLog: infoLog,
@ -80,7 +80,21 @@ func main() {
app.errorLog.Fatal(err) app.errorLog.Fatal(err)
} }
mux.HandleFunc("newcringe", newCringe) mux.HandleFunc("cringe", app.sendCringe)
mux.HandleFunc("gif", app.sendNigelGif)
mux.HandleFunc("tuesday", app.sendTuesday)
mux.HandleFunc("wednesday", app.sendWednesday)
mux.HandleFunc("github", app.sendGithub)
mux.HandleFunc("source", app.sendGithub)
/* The admin commands are left out for now.
They have specialised functions and don't work yet.
Their code is left unworking and nonfunctional to be fixed
sometime in the future... sometime
Another thing left out is the bad words feature.
It goes underused and has had it's joke.
Oh and no one must be sad to see the death of the spam command...*/
mux.HandleFunc(mux.prefix, app.sendPepe) mux.HandleFunc(mux.prefix, app.sendPepe)
/* token, err := app.readAuthToken() /* token, err := app.readAuthToken()