Add debug level command

This commit is contained in:
2021-05-06 07:36:52 -04:00
parent fa53c8b1da
commit 2a5fe0ceef

View File

@ -8,6 +8,8 @@ import (
"strconv"
"strings"
"time"
"github.com/rudi9719/loggy"
)
func setupCommands() {
@ -69,6 +71,15 @@ func setupCommands() {
Exec: Commands,
}
commands = append(commands, listCommands)
debugLevel := Command{
Name: "Debug Level",
RequiresAdmin: true,
Keywords: []string{"debug"},
Exec: Debug,
Help: "Set the log level for loggy",
}
commands = append(commands, debugLevel)
}
func Commands(b BotCommand) bool {
@ -87,6 +98,17 @@ func Commands(b BotCommand) bool {
return true
}
func Debug(b BotCommand) bool {
defer log.PanicSafe()
level, err := strconv.Atoi(b.Parts[0])
if err != nil {
return false
}
config.LogOpts.Level = loggy.LogLevel(level)
log = loggy.NewLogger(config.LogOpts)
return true
}
func Reboot(b BotCommand) bool {
defer log.PanicSafe()
if strings.Contains(b.Message.Content, rebootToken) {