mirror of
https://github.com/lyx0/nourybot-matrix.git
synced 2024-11-13 19:49:54 +01:00
add how many commands have been used to ping command
This commit is contained in:
parent
f78e83e6f1
commit
ab83e11624
3 changed files with 26 additions and 1 deletions
|
@ -4,10 +4,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lyx0/nourybot-matrix/internal/commands"
|
"github.com/lyx0/nourybot-matrix/internal/commands"
|
||||||
|
"github.com/lyx0/nourybot-matrix/internal/common"
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (app *Application) ParseCommand(evt *event.Event) {
|
func (app *Application) ParseCommand(evt *event.Event) {
|
||||||
|
common.CommandUsed()
|
||||||
// commandName is the actual name of the command without the prefix.
|
// commandName is the actual name of the command without the prefix.
|
||||||
// e.g. `!ping` would be `ping`.
|
// e.g. `!ping` would be `ping`.
|
||||||
commandName := strings.ToLower(strings.SplitN(evt.Content.AsMessage().Body, " ", 2)[0][1:])
|
commandName := strings.ToLower(strings.SplitN(evt.Content.AsMessage().Body, " ", 2)[0][1:])
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/lyx0/nourybot-matrix/internal/common"
|
||||||
|
)
|
||||||
|
|
||||||
func Ping() (string, error) {
|
func Ping() (string, error) {
|
||||||
resp := "Pong!"
|
n := common.GetCommandsUsed()
|
||||||
|
resp := fmt.Sprintf("Pong! Commands used: %v", n)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
16
internal/common/counter.go
Normal file
16
internal/common/counter.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
var (
|
||||||
|
tempCommands = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
// CommandUsed is called on every command incremenenting tempCommands.
|
||||||
|
func CommandUsed() {
|
||||||
|
tempCommands++
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCommandsUsed returns the amount of commands that have been used
|
||||||
|
// since the last restart.
|
||||||
|
func GetCommandsUsed() int {
|
||||||
|
return tempCommands
|
||||||
|
}
|
Loading…
Reference in a new issue