mirror-nourybot/pkg/handlers/command.go

44 lines
1,023 B
Go
Raw Normal View History

package handlers
2021-10-14 00:19:35 +02:00
import (
2021-10-19 22:33:08 +02:00
"strings"
2021-10-14 00:19:35 +02:00
"github.com/gempir/go-twitch-irc/v2"
2021-10-19 22:25:47 +02:00
"github.com/lyx0/nourybot/cmd/bot"
2021-10-19 22:39:25 +02:00
"github.com/lyx0/nourybot/pkg/commands"
2021-10-19 22:25:47 +02:00
"github.com/sirupsen/logrus"
2021-10-14 00:19:35 +02:00
)
2021-10-19 22:25:47 +02:00
func Command(message twitch.PrivateMessage, nb *bot.Bot) {
logrus.Info("fn Command")
2021-10-14 01:30:29 +02:00
2021-10-19 22:33:08 +02:00
// commandName is the actual command name without the prefix.
commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:])
// cmdParams are additional command inputs.
// example:
// weather san antonio
// is
// commandName cmdParams[0] cmdParams[1]
cmdParams := strings.SplitN(message.Message, " ", 500)
// msgLen is the amount of words in the message without the prefix.
// Useful for checking if enough cmdParams are given.
msgLen := len(strings.SplitN(message.Message, " ", -2))
switch commandName {
case "":
if msgLen == 1 {
nb.Send(message.Channel, "xd")
}
case "echo":
if msgLen != 1 {
nb.Send(message.Channel, cmdParams[1])
return
}
2021-10-19 22:39:25 +02:00
case "ping":
commands.Ping(message.Channel, nb)
2021-10-19 22:33:08 +02:00
}
2021-10-15 18:35:16 +02:00
2021-10-14 00:19:35 +02:00
}