2021-10-14 01:36:42 +02:00
|
|
|
package handlers
|
2021-10-14 00:19:35 +02:00
|
|
|
|
|
|
|
import (
|
2021-10-14 01:30:29 +02:00
|
|
|
"strings"
|
2021-10-14 19:02:07 +02:00
|
|
|
"time"
|
2021-10-14 01:30:29 +02:00
|
|
|
|
2021-10-14 00:19:35 +02:00
|
|
|
"github.com/gempir/go-twitch-irc/v2"
|
2021-10-14 18:46:16 +02:00
|
|
|
"github.com/lyx0/nourybot/pkg/commands"
|
|
|
|
"github.com/lyx0/nourybot/pkg/utils"
|
2021-10-14 00:19:35 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2021-10-14 01:30:29 +02:00
|
|
|
// HandleCommand receives a twitch.PrivateMessage from
|
|
|
|
// HandlePrivateMessage where it found a command in it.
|
|
|
|
// HandleCommand passes on the message to the specific
|
|
|
|
// command handler for further action.
|
2021-10-14 19:02:07 +02:00
|
|
|
func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, uptime time.Time) {
|
2021-10-14 00:19:35 +02:00
|
|
|
log.Info("fn HandleCommand")
|
2021-10-14 01:30:29 +02:00
|
|
|
|
2021-10-14 18:46:16 +02:00
|
|
|
// Counter that increments on every command call.
|
|
|
|
utils.CommandUsed()
|
|
|
|
|
2021-10-14 01:30:29 +02:00
|
|
|
// commandName is the actual command name without the prefix.
|
2021-10-14 22:22:05 +02:00
|
|
|
commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:])
|
2021-10-14 01:30:29 +02:00
|
|
|
|
|
|
|
// 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 {
|
|
|
|
twitchClient.Say(message.Channel, "Why yes, that's my prefix :)")
|
2021-10-16 18:06:34 +02:00
|
|
|
return
|
2021-10-14 01:30:29 +02:00
|
|
|
}
|
2021-10-17 10:23:36 +02:00
|
|
|
case "botstatus":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()botstatus [username]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.BotStatus(message.Channel, cmdParams[1], twitchClient)
|
|
|
|
return
|
|
|
|
}
|
2021-10-16 18:06:34 +02:00
|
|
|
case "bttvemotes":
|
|
|
|
commands.BttvEmotes(message.Channel, twitchClient)
|
2021-10-14 01:30:29 +02:00
|
|
|
return
|
2021-10-14 22:05:12 +02:00
|
|
|
case "cf":
|
|
|
|
commands.Coinflip(message.Channel, twitchClient)
|
|
|
|
return
|
|
|
|
case "coin":
|
|
|
|
commands.Coinflip(message.Channel, twitchClient)
|
|
|
|
return
|
|
|
|
case "coinflip":
|
|
|
|
commands.Coinflip(message.Channel, twitchClient)
|
|
|
|
return
|
2021-10-14 22:18:31 +02:00
|
|
|
case "color":
|
|
|
|
commands.Color(message, twitchClient)
|
|
|
|
return
|
2021-10-14 22:22:05 +02:00
|
|
|
case "mycolor":
|
|
|
|
commands.Color(message, twitchClient)
|
|
|
|
return
|
2021-10-15 18:44:52 +02:00
|
|
|
case "echo":
|
|
|
|
commands.Echo(message.Channel, message.Message[7:len(message.Message)], twitchClient)
|
|
|
|
return
|
2021-10-14 22:32:00 +02:00
|
|
|
case "8ball":
|
2021-10-17 17:56:19 +02:00
|
|
|
commands.EightBall(message.Channel, twitchClient)
|
2021-10-14 22:32:00 +02:00
|
|
|
return
|
2021-10-16 18:24:50 +02:00
|
|
|
case "ffzemotes":
|
|
|
|
commands.FfzEmotes(message.Channel, twitchClient)
|
|
|
|
return
|
2021-10-15 18:44:52 +02:00
|
|
|
case "fill":
|
2021-10-14 22:56:08 +02:00
|
|
|
if msgLen == 1 {
|
2021-10-15 18:44:52 +02:00
|
|
|
twitchClient.Say(message.Channel, "Usage: ()fill [emote]")
|
2021-10-14 23:05:56 +02:00
|
|
|
return
|
2021-10-14 22:56:08 +02:00
|
|
|
} else {
|
2021-10-15 18:44:52 +02:00
|
|
|
commands.Fill(message.Channel, message.Message[7:len(message.Message)], twitchClient)
|
2021-10-14 22:56:08 +02:00
|
|
|
return
|
|
|
|
}
|
2021-10-17 18:43:38 +02:00
|
|
|
case "firstline":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()firstline [channel] [user]")
|
|
|
|
return
|
|
|
|
} else if msgLen == 2 {
|
|
|
|
commands.Firstline(message.Channel, message.Channel, cmdParams[1], twitchClient)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Firstline(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
|
|
|
|
return
|
|
|
|
}
|
2021-10-17 18:55:51 +02:00
|
|
|
case "followage":
|
|
|
|
if msgLen <= 2 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()followage [channel] [user]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Followage(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
|
|
|
|
return
|
|
|
|
}
|
2021-10-16 18:48:59 +02:00
|
|
|
case "game":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()game [channel]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Game(message.Channel, cmdParams[1], twitchClient)
|
|
|
|
}
|
2021-10-14 23:04:41 +02:00
|
|
|
case "godoc":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()godoc [term]")
|
2021-10-14 23:05:56 +02:00
|
|
|
return
|
2021-10-14 23:04:41 +02:00
|
|
|
} else {
|
|
|
|
commands.Godocs(message.Channel, message.Message[8:len(message.Message)], twitchClient)
|
2021-10-14 23:05:56 +02:00
|
|
|
return
|
2021-10-14 23:04:41 +02:00
|
|
|
}
|
|
|
|
case "godocs":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()godoc [term]")
|
2021-10-14 23:05:56 +02:00
|
|
|
return
|
2021-10-14 23:04:41 +02:00
|
|
|
} else {
|
|
|
|
commands.Godocs(message.Channel, message.Message[9:len(message.Message)], twitchClient)
|
2021-10-14 23:05:56 +02:00
|
|
|
return
|
2021-10-14 23:04:41 +02:00
|
|
|
}
|
2021-10-15 18:44:52 +02:00
|
|
|
case "ping":
|
|
|
|
commands.Ping(message.Channel, twitchClient, uptime)
|
|
|
|
return
|
|
|
|
case "pingme":
|
|
|
|
commands.Pingme(message.Channel, message.User.DisplayName, twitchClient)
|
2021-10-16 18:48:59 +02:00
|
|
|
return
|
2021-10-15 18:21:17 +02:00
|
|
|
case "pyramid":
|
|
|
|
if msgLen != 3 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()pyramid [size] [emote]")
|
|
|
|
} else if utils.ElevatedPrivsMessage(message) {
|
|
|
|
commands.Pyramid(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
|
|
|
|
} else {
|
|
|
|
twitchClient.Say(message.Channel, "Pleb's can't pyramid FeelsBadMan")
|
|
|
|
}
|
2021-10-16 00:56:08 +02:00
|
|
|
|
|
|
|
case "subage":
|
|
|
|
if msgLen < 3 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()subage [user] [streamer]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Subage(message.Channel, cmdParams[1], cmdParams[2], twitchClient)
|
2021-10-16 18:24:50 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
case "thumb":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()thumbnail [channel]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Thumbnail(message.Channel, cmdParams[1], twitchClient)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "thumbnail":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()thumbnail [channel]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Thumbnail(message.Channel, cmdParams[1], twitchClient)
|
|
|
|
return
|
2021-10-16 00:56:08 +02:00
|
|
|
}
|
2021-10-15 18:44:52 +02:00
|
|
|
case "uptime":
|
|
|
|
if msgLen == 1 {
|
|
|
|
commands.Uptime(message.Channel, message.Channel, twitchClient)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Uptime(message.Channel, cmdParams[1], twitchClient)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "weather":
|
|
|
|
if msgLen == 1 {
|
|
|
|
twitchClient.Say(message.Channel, "Usage: ()weather [location]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Weather(message.Channel, message.Message[9:len(message.Message)], twitchClient)
|
|
|
|
return
|
|
|
|
}
|
2021-10-15 18:45:17 +02:00
|
|
|
case "xd":
|
|
|
|
commands.Xd(message.Channel, twitchClient)
|
|
|
|
return
|
2021-10-15 18:35:16 +02:00
|
|
|
|
2021-10-14 00:19:35 +02:00
|
|
|
}
|
2021-10-15 18:44:52 +02:00
|
|
|
|
2021-10-14 00:19:35 +02:00
|
|
|
}
|