From 18363b0dee51197182b9223ec5e6eab013b2fa08 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Thu, 14 Oct 2021 18:46:16 +0200 Subject: [PATCH] add command counter --- pkg/commands/ping.go | 15 +++++++++++++++ pkg/handlers/command.go | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 pkg/commands/ping.go diff --git a/pkg/commands/ping.go b/pkg/commands/ping.go new file mode 100644 index 0000000..d86dad3 --- /dev/null +++ b/pkg/commands/ping.go @@ -0,0 +1,15 @@ +package commands + +import ( + "fmt" + + "github.com/gempir/go-twitch-irc/v2" + "github.com/lyx0/nourybot/pkg/utils" +) + +func PingCommand(channel string, client *twitch.Client) { + commandCount := fmt.Sprint(utils.GetCommandsUsed()) + + s := fmt.Sprintf("Pong! :) Commands used: %v", commandCount) + client.Say(channel, s) +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index d25ae36..41e4bac 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -4,6 +4,8 @@ import ( "strings" "github.com/gempir/go-twitch-irc/v2" + "github.com/lyx0/nourybot/pkg/commands" + "github.com/lyx0/nourybot/pkg/utils" log "github.com/sirupsen/logrus" ) @@ -14,6 +16,9 @@ import ( func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) { log.Info("fn HandleCommand") + // Counter that increments on every command call. + utils.CommandUsed() + // commandName is the actual command name without the prefix. commandName := strings.SplitN(message.Message, " ", 3)[0][2:] @@ -40,5 +45,7 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) { case "echo": twitchClient.Say(message.Channel, cmdParams[1]) return + case "ping": + commands.PingCommand(message.Channel, twitchClient) } }