mirror-nourybot/cmd/bot/command.go

251 lines
6.9 KiB
Go
Raw Normal View History

2022-08-07 01:34:31 +02:00
package main
2022-06-21 00:31:17 +02:00
import (
"strings"
"github.com/gempir/go-twitch-irc/v3"
2022-08-07 01:34:31 +02:00
"github.com/lyx0/nourybot/pkg/commands"
2022-08-07 02:27:40 +02:00
"github.com/lyx0/nourybot/pkg/common"
2022-08-07 03:09:09 +02:00
"go.uber.org/zap"
2022-06-21 00:31:17 +02:00
)
func (app *Application) handleCommand(message twitch.PrivateMessage) {
2022-08-07 03:09:09 +02:00
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
2022-08-07 17:24:47 +02:00
// Increments the counter how many commands were used.
common.CommandUsed()
2022-06-21 00:31:17 +02:00
// commandName is the actual name of the command without the prefix.
// e.g. `()ping` would be `ping`.
commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:])
// cmdParams are additional command parameters.
// e.g. `()weather san antonio`
// cmdParam[0] is `san` and cmdParam[1] = `antonio`.
//
// Since Twitch messages are at most 500 characters I use a
// maximum count of 500+10 just to be safe.
// https://discuss.dev.twitch.tv/t/missing-client-side-message-length-check/21316
2022-08-07 02:27:40 +02:00
cmdParams := strings.SplitN(message.Message, " ", 500)
2022-06-21 00:31:17 +02:00
_ = cmdParams
// msgLen is the amount of words in a message without the prefix.
// Useful to check if enough cmdParams are provided.
msgLen := len(strings.SplitN(message.Message, " ", -2))
// target is the channelname the message originated from and
// where we are responding.
target := message.Channel
2022-08-07 03:17:29 +02:00
sugar.Infow("Command received",
// "message", message,
2022-08-07 04:35:03 +02:00
"message.Channel", target,
2022-08-07 03:17:29 +02:00
"message.Message", message.Message,
"commandName", commandName,
"cmdParams", cmdParams,
"msgLen", msgLen,
)
2022-06-21 00:31:17 +02:00
switch commandName {
case "":
if msgLen == 1 {
2022-08-08 23:12:50 +02:00
common.Send(target, "xd", app.TwitchClient)
2022-06-21 00:31:17 +02:00
return
}
2022-08-09 01:09:53 +02:00
case "addchannel":
if message.User.ID != "31437432" { // Limit to myself for now.
return
} else if msgLen < 2 {
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
return
} else {
// ()addchannel noemience
app.AddChannel(cmdParams[1], message)
2022-08-09 01:09:53 +02:00
return
}
case "adduser":
if message.User.ID != "31437432" { // Limit to myself for now.
return
} else if msgLen < 3 {
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
return
} else {
// ()adduser nourylul 1000
app.AddUser(cmdParams[1], cmdParams[2], message)
return
}
2022-08-09 19:50:46 +02:00
case "deletechannel":
if message.User.ID != "31437432" { // Limit to myself for now.
return
} else if msgLen < 2 {
2022-08-09 19:50:46 +02:00
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
return
} else {
// ()addchannel noemience
app.DeleteChannel(cmdParams[1], message)
2022-08-09 19:50:46 +02:00
return
}
case "deleteuser":
if message.User.ID != "31437432" { // Limit to myself for now.
return
} else if msgLen < 2 {
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
return
} else {
// ()addchannel noemience
app.DeleteUser(cmdParams[1], message)
return
}
2022-08-07 21:43:40 +02:00
case "bttv":
if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()bttv <emote name>", app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Bttv(target, cmdParams[1], app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
}
case "bttvemotes": // Pretty spammy command so it's limited to my own channel until elevated messages are implemented.
2022-08-07 18:10:40 +02:00
if target == "nourylul" || target == "nourybot" {
2022-08-08 23:12:50 +02:00
commands.Bttvemotes(target, app.TwitchClient)
2022-08-07 18:10:40 +02:00
return
} else {
return
}
2022-08-08 13:17:42 +02:00
case "coin":
2022-08-08 23:12:50 +02:00
commands.Coinflip(target, app.TwitchClient)
2022-08-08 13:17:42 +02:00
return
case "coinflip":
2022-08-08 23:12:50 +02:00
commands.Coinflip(target, app.TwitchClient)
2022-08-08 13:17:42 +02:00
return
case "cf":
2022-08-08 23:12:50 +02:00
commands.Coinflip(target, app.TwitchClient)
2022-08-08 13:17:42 +02:00
return
2022-08-07 17:24:47 +02:00
case "currency":
if msgLen < 4 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()currency 10 USD to EUR", app.TwitchClient)
2022-08-07 17:24:47 +02:00
return
}
2022-08-08 23:12:50 +02:00
commands.Currency(target, cmdParams[1], cmdParams[2], cmdParams[4], app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
2022-06-21 00:31:17 +02:00
case "echo":
2022-08-07 21:43:40 +02:00
if message.User.ID != "31437432" { // Limit to myself for now.
return
} else if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
2022-06-21 00:31:17 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Echo(target, message.Message[7:len(message.Message)], app.TwitchClient)
2022-06-21 00:31:17 +02:00
return
}
2022-08-08 16:43:21 +02:00
2022-08-07 21:43:40 +02:00
case "ffz":
if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()ffz <emote name>", app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Ffz(target, cmdParams[1], app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
}
case "ffzemotes": // Pretty spammy command so it's limited to my own channel until elevated messages are implemented.
2022-08-07 18:10:40 +02:00
if target == "nourylul" || target == "nourybot" {
2022-08-08 23:12:50 +02:00
commands.Ffzemotes(target, app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
} else {
return
}
2022-08-08 16:43:21 +02:00
// Followage
// ()followage channel username
case "followage":
if msgLen == 1 { // ()followage
2022-08-08 23:12:50 +02:00
commands.Followage(target, target, message.User.Name, app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
} else if msgLen == 2 { // ()followage forsen
2022-08-08 23:12:50 +02:00
commands.Followage(target, target, cmdParams[1], app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
} else { // ()followage forsen pajlada
2022-08-08 23:12:50 +02:00
commands.Followage(target, cmdParams[1], cmdParams[2], app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
}
// First Line
case "firstline":
if msgLen == 1 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Usage: ()firstline <channel> <user>", app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
} else if msgLen == 2 {
2022-08-08 23:12:50 +02:00
commands.FirstLine(target, target, cmdParams[1], app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.FirstLine(target, cmdParams[1], cmdParams[2], app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
}
case "fl":
if msgLen == 1 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Usage: ()firstline <channel> <user>", app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
} else if msgLen == 2 {
2022-08-08 23:12:50 +02:00
commands.FirstLine(target, target, cmdParams[1], app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.FirstLine(target, cmdParams[1], cmdParams[2], app.TwitchClient)
2022-08-08 16:43:21 +02:00
return
}
2022-08-07 21:43:40 +02:00
case "ping":
2022-08-08 23:12:50 +02:00
commands.Ping(target, app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
case "preview":
if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()preview <username>", app.TwitchClient)
2022-08-07 18:10:40 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Preview(target, cmdParams[1], app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
}
2022-08-08 16:43:21 +02:00
case "thumbnail":
2022-08-08 13:45:37 +02:00
if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()thumbnail <username>", app.TwitchClient)
2022-08-08 13:45:37 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Preview(target, cmdParams[1], app.TwitchClient)
2022-08-08 13:45:37 +02:00
return
}
2022-08-08 16:43:21 +02:00
// SevenTV
case "seventv":
2022-08-08 13:45:37 +02:00
if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()seventv <emote name>", app.TwitchClient)
2022-08-08 13:45:37 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Seventv(target, cmdParams[1], app.TwitchClient)
2022-08-08 13:45:37 +02:00
return
}
2022-08-08 16:43:21 +02:00
case "7tv":
2022-08-07 21:43:40 +02:00
if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()seventv <emote name>", app.TwitchClient)
2022-08-07 21:43:40 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Seventv(target, cmdParams[1], app.TwitchClient)
2022-08-07 18:10:40 +02:00
return
}
2022-08-07 16:08:30 +02:00
case "tweet":
if msgLen < 2 {
2022-08-08 23:12:50 +02:00
common.Send(target, "Not enough arguments provided. Usage: ()tweet <username>", app.TwitchClient)
2022-08-07 16:08:30 +02:00
return
} else {
2022-08-08 23:12:50 +02:00
commands.Tweet(target, cmdParams[1], app.TwitchClient)
2022-08-07 16:08:30 +02:00
}
2022-08-08 13:45:37 +02:00
case "rxkcd":
2022-08-08 23:12:50 +02:00
commands.RandomXkcd(target, app.TwitchClient)
2022-08-08 13:45:37 +02:00
return
case "randomxkcd":
2022-08-08 23:12:50 +02:00
commands.RandomXkcd(target, app.TwitchClient)
2022-08-08 13:45:37 +02:00
return
case "xkcd":
2022-08-08 23:12:50 +02:00
commands.Xkcd(target, app.TwitchClient)
2022-08-08 13:45:37 +02:00
return
2022-06-21 00:31:17 +02:00
}
}