From b832ec63b6d0f12359977764a2603d61f67559a4 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Thu, 11 Aug 2022 23:34:00 +0200 Subject: [PATCH] make the commandPrefix a config value --- cmd/bot/command.go | 2 +- cmd/bot/main.go | 7 +++++-- cmd/bot/models.go | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/bot/command.go b/cmd/bot/command.go index 9e1363d..d8ccb42 100644 --- a/cmd/bot/command.go +++ b/cmd/bot/command.go @@ -47,9 +47,9 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { app.Logger.Infow("Command received", // "message", message, + "message.Message", message.Message, "message.Channel", target, "user level", userLevel, - "message.Message", message.Message, "commandName", commandName, "cmdParams", cmdParams, "msgLen", msgLen, diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 3cb712c..45be81e 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -33,7 +33,8 @@ func main() { cfg.twitchOauth = os.Getenv("TWITCH_OAUTH") tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth) - // Environment + // Basic configuration + cfg.commandPrefix = "()" cfg.environment = "Development" // Database @@ -77,8 +78,10 @@ func main() { // Message was shorter than our prefix is therefore it's irrelevant for us. if len(message.Message) >= 2 { + // This bots prefix is "()" configured above at `cfg.commandPrefix`, // Check if the first 2 characters of the mesage were our prefix. - if message.Message[:2] == "()" { + // if they were forward the message to the command handler. + if message.Message[:2] == cfg.commandPrefix { app.handleCommand(message) return } diff --git a/cmd/bot/models.go b/cmd/bot/models.go index 3385841..975f6a0 100644 --- a/cmd/bot/models.go +++ b/cmd/bot/models.go @@ -19,6 +19,7 @@ var ( type config struct { twitchUsername string twitchOauth string + commandPrefix string environment string db struct { dsn string