From b8625e1901a4209962a9620f0cb78a411b896628 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Sat, 4 Mar 2023 05:00:00 +0000 Subject: [PATCH] add a command to debug commands and output information about a provided command name --- cmd/bot/command.go | 37 +++++++++++++++++++++++++++++++++++++ cmd/bot/commands.go | 4 ++++ 2 files changed, 41 insertions(+) diff --git a/cmd/bot/command.go b/cmd/bot/command.go index b694ae5..e0bfe05 100644 --- a/cmd/bot/command.go +++ b/cmd/bot/command.go @@ -157,6 +157,43 @@ func (app *Application) EditCommandCategory(name, category string, message twitc } } +// DebugCommand checks if a command with the provided name exists in the database +// and outputs information about it in the chat. +func (app *Application) DebugCommand(name string, message twitch.PrivateMessage) { + // Query the database for a command with the provided name + cmd, err := app.Models.Commands.Get(name) + if err != nil { + reply := fmt.Sprintf("Something went wrong FeelsBadMan %s", err) + common.Send(message.Channel, reply, app.TwitchClient) + return + } else if cmd.Category == "ascii" { + // If the command is in the ascii category don't post the Text field + // otherwise it becomes too spammy and won't fit in the max message length. + reply := fmt.Sprintf("ID %v: Name %v, Level: %v, Category: %v Help: %v", + cmd.ID, + cmd.Name, + cmd.Level, + cmd.Category, + cmd.Help, + ) + + common.Send(message.Channel, reply, app.TwitchClient) + return + } else { + reply := fmt.Sprintf("ID %v: Name %v, Level: %v, Category: %v, Text: %v, Help: %v", + cmd.ID, + cmd.Name, + cmd.Level, + cmd.Category, + cmd.Text, + cmd.Help, + ) + + common.Send(message.Channel, reply, app.TwitchClient) + return + } +} + // SetCommandHelp updates the `help` column of a given commands name in the // database to the provided new help text. func (app *Application) EditCommandHelp(name string, message twitch.PrivateMessage) { diff --git a/cmd/bot/commands.go b/cmd/bot/commands.go index 2f8c2f2..45be700 100644 --- a/cmd/bot/commands.go +++ b/cmd/bot/commands.go @@ -246,6 +246,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { // 250 - VIP only //################# // ()debug user + // ()debug command case "debug": if userLevel < 250 { return @@ -255,6 +256,9 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { } else if cmdParams[1] == "user" { app.DebugUser(cmdParams[2], message) return + } else if cmdParams[1] == "command" { + app.DebugCommand(cmdParams[2], message) + return } else { return }