added middleware

This commit is contained in:
DutchEllie 2021-06-03 13:45:07 +02:00
parent 9f1d13d3aa
commit ebbbc3680d
2 changed files with 14 additions and 2 deletions

View File

@ -64,8 +64,6 @@ func main() {
mux := NewCommandMux()
mux.prefix = "!newpepe"
mux.HandleFunc("newcringe", newCringe)
mux.HandleFunc(mux.prefix, newSendPepe)
app := &application{
infoLog: infoLog,
@ -82,6 +80,9 @@ func main() {
app.errorLog.Fatal(err)
}
mux.Handle("newcringe", app.LogToConsole(HandlerFunc(newCringe)))
mux.HandleFunc(mux.prefix, app.sendPepe)
/* token, err := app.readAuthToken()
if err != nil {
app.errorLog.Fatal(err)

11
discord/middleware.go Normal file
View File

@ -0,0 +1,11 @@
package main
import "github.com/bwmarrin/discordgo"
func (app *application) LogToConsole(next Command) Command {
fn := func(s *discordgo.Session, m *discordgo.MessageCreate) {
app.infoLog.Printf("%s \tsaid: %s\n", m.Author.Username, m.Content)
next.Execute(s, m)
}
return HandlerFunc(fn)
}