add command counter

This commit is contained in:
lyx0 2021-10-14 18:46:16 +02:00
parent 2ce5f432b5
commit 18363b0dee
2 changed files with 22 additions and 0 deletions

15
pkg/commands/ping.go Normal file
View file

@ -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)
}

View file

@ -4,6 +4,8 @@ import (
"strings" "strings"
"github.com/gempir/go-twitch-irc/v2" "github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/pkg/commands"
"github.com/lyx0/nourybot/pkg/utils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -14,6 +16,9 @@ import (
func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) { func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) {
log.Info("fn HandleCommand") log.Info("fn HandleCommand")
// Counter that increments on every command call.
utils.CommandUsed()
// commandName is the actual command name without the prefix. // commandName is the actual command name without the prefix.
commandName := strings.SplitN(message.Message, " ", 3)[0][2:] commandName := strings.SplitN(message.Message, " ", 3)[0][2:]
@ -40,5 +45,7 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) {
case "echo": case "echo":
twitchClient.Say(message.Channel, cmdParams[1]) twitchClient.Say(message.Channel, cmdParams[1])
return return
case "ping":
commands.PingCommand(message.Channel, twitchClient)
} }
} }