mirror of
https://github.com/Xevion/banner.git
synced 2025-12-12 01:09:22 -06:00
Improve command handler main logging & error logs
This commit is contained in:
16
main.go
16
main.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
"os"
|
"os"
|
||||||
@@ -145,9 +146,22 @@ func main() {
|
|||||||
session.AddHandler(func(internalSession *discordgo.Session, interaction *discordgo.InteractionCreate) {
|
session.AddHandler(func(internalSession *discordgo.Session, interaction *discordgo.InteractionCreate) {
|
||||||
name := interaction.ApplicationCommandData().Name
|
name := interaction.ApplicationCommandData().Name
|
||||||
if handler, ok := commandHandlers[name]; ok {
|
if handler, ok := commandHandlers[name]; ok {
|
||||||
|
// Build dict of options for the log
|
||||||
|
options := zerolog.Dict()
|
||||||
|
for _, option := range interaction.ApplicationCommandData().Options {
|
||||||
|
options.Str(option.Name, fmt.Sprintf("%v", option.Value))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log command invocation
|
||||||
|
log.Info().Str("name", name).Str("user", interaction.Member.User.Username).Dict("options", options).Msg("Command Invoked")
|
||||||
|
|
||||||
|
// Call handler
|
||||||
handler(internalSession, interaction)
|
handler(internalSession, interaction)
|
||||||
} else {
|
} else {
|
||||||
log.Warn().Str("commandName", name).Msg("Unknown command")
|
log.Error().Str("commandName", name).Msg("Command Interaction Has No Handler")
|
||||||
|
|
||||||
|
// Respond with error
|
||||||
|
RespondError(internalSession, interaction.Interaction, "Command not found", nil)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user