mirror-nourybot/pkg/handlers/command.go

569 lines
11 KiB
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"
"github.com/lyx0/nourybot/pkg/commands/personal"
2021-10-28 16:16:11 +02:00
"github.com/lyx0/nourybot/pkg/db"
2021-10-19 23:53:41 +02:00
"github.com/lyx0/nourybot/pkg/utils"
2021-10-14 00:19:35 +02:00
)
2021-10-21 00:07:18 +02:00
// Command contains all the logic for routing mesasges containing commands
// and will forward the messages to the specific command handlers.
2021-10-19 22:25:47 +02:00
func Command(message twitch.PrivateMessage, nb *bot.Bot) {
2021-10-20 00:33:17 +02:00
utils.CommandUsed()
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.
2021-10-21 00:08:09 +02:00
// example: "weather san antonion
// is: commandName cmdParams[0] cmdParams[1]
2021-10-19 22:33:08 +02:00
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))
2021-10-19 23:27:55 +02:00
// target channel
target := message.Channel
2021-12-13 20:53:24 +01:00
// Logs the message to the database since it invoked a command.
db.InsertCommand(nb, commandName, message.User.Name, message.Channel, message.User.ID, message.Message)
2021-10-19 22:33:08 +02:00
switch commandName {
case "":
if msgLen == 1 {
2021-10-19 23:27:55 +02:00
nb.Send(target, "xd")
2021-10-23 22:15:29 +02:00
return
2021-10-19 23:27:55 +02:00
}
2021-12-13 20:53:24 +01:00
2021-10-24 17:48:00 +02:00
case "7tv":
if msgLen == 1 {
nb.Send(target, "Usage: ()7tv [emote]")
return
}
commands.SevenTV(target, cmdParams[1], nb)
return
2021-10-21 01:43:10 +02:00
2021-10-28 18:15:17 +02:00
case "8ball":
commands.EightBall(target, nb)
return
2021-10-23 22:15:29 +02:00
case "bot":
commands.Help(target, nb)
return
case "botinfo":
commands.Help(target, nb)
return
2021-10-19 23:27:55 +02:00
case "botstatus":
if msgLen == 1 {
nb.Send(target, "Usage: ()botstatus [username]")
return
} else {
commands.BotStatus(target, cmdParams[1], nb)
return
2021-10-19 22:33:08 +02:00
}
2021-10-21 01:43:10 +02:00
2021-10-23 21:59:56 +02:00
case "bttv":
if msgLen == 1 {
nb.Send(target, "Usage: ()bttv [emote]")
return
}
commands.Bttv(target, cmdParams[1], nb)
return
2021-10-23 22:11:23 +02:00
2021-11-01 19:34:32 +01:00
case "channellist":
if message.User.ID != "31437432" {
nb.Send(target, "You are not allowed to do this")
return
}
commands.ChannelList(target, nb)
return
2021-10-25 13:52:09 +02:00
// case "bttvemotes":
// commands.BttvEmotes(target, nb)
// return
2021-10-21 01:43:10 +02:00
2021-10-28 18:15:17 +02:00
case "cat":
commands.RandomCat(target, nb)
return
2021-10-19 23:27:55 +02:00
case "cf":
commands.Coinflip(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:27:55 +02:00
case "coin":
commands.Coinflip(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:27:55 +02:00
case "coinflip":
commands.Coinflip(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:27:55 +02:00
case "color":
commands.Color(cmdParams[1], target, nb)
2021-10-19 23:27:55 +02:00
return
2021-10-21 01:43:10 +02:00
2021-10-23 22:15:29 +02:00
case "commands":
commands.CommandsList(target, nb)
return
2021-10-28 18:15:17 +02:00
case "dog":
commands.RandomDog(target, nb)
return
case "duck":
commands.RandomDuck(target, nb)
2021-10-19 23:27:55 +02:00
return
2021-10-21 01:43:10 +02:00
2021-10-23 19:48:50 +02:00
case "currency":
2021-10-23 20:40:40 +02:00
if msgLen <= 4 {
nb.Send(target, "Usage: ()currency 10 usd to eur, only 3 letter codes work.")
return
}
2021-10-23 19:48:50 +02:00
commands.Currency(target, cmdParams[1], cmdParams[2], cmdParams[4], nb)
2021-10-23 20:43:39 +02:00
return
2021-10-19 22:33:08 +02:00
case "echo":
2021-11-02 19:48:44 +01:00
if message.User.ID != "31437432" {
2021-12-13 20:53:24 +01:00
// nb.Send(target, "You're not authorized to do this.")
2021-11-02 19:48:44 +01:00
return
} else {
commands.Echo(target, message.Message[7:len(message.Message)], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-22 17:59:45 +02:00
case "emote":
commands.EmoteLookup(target, cmdParams[1], nb)
2021-10-31 14:25:47 +01:00
return
2021-10-22 17:59:45 +02:00
case "emotelookup":
commands.EmoteLookup(target, cmdParams[1], nb)
2021-10-31 14:25:47 +01:00
return
2021-10-22 17:59:45 +02:00
2021-10-23 21:59:56 +02:00
case "ffz":
if msgLen == 1 {
nb.Send(target, "Usage: ()ffz [emote]")
return
}
commands.Ffz(target, cmdParams[1], nb)
2021-10-31 14:25:47 +01:00
return
2021-10-25 13:52:09 +02:00
2021-12-13 20:53:24 +01:00
// case "ffzemotes":
2021-10-25 13:52:09 +02:00
// commands.FfzEmotes(target, nb)
// return
2021-10-19 23:27:55 +02:00
case "fill":
2021-11-02 19:48:44 +01:00
if message.User.ID != "31437432" {
nb.Send(target, "You're not authorized to do this.")
return
} else if msgLen == 1 {
2021-10-19 23:27:55 +02:00
nb.Send(target, "Usage: ()fill [emote]")
return
} else {
commands.Fill(target, message.Message[7:len(message.Message)], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:27:55 +02:00
case "firstline":
if msgLen == 1 {
nb.Send(target, "Usage: ()firstline [channel] [user]")
return
} else if msgLen == 2 {
2021-10-19 23:53:41 +02:00
commands.Firstline(target, target, cmdParams[1], nb)
2021-10-19 23:27:55 +02:00
return
} else {
commands.Firstline(target, cmdParams[1], cmdParams[2], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:27:55 +02:00
case "fl":
if msgLen == 1 {
nb.Send(target, "Usage: ()firstline [channel] [user]")
return
} else if msgLen == 2 {
2021-10-19 23:53:41 +02:00
commands.Firstline(target, target, cmdParams[1], nb)
2021-10-19 23:27:55 +02:00
return
} else {
commands.Firstline(target, cmdParams[1], cmdParams[2], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:27:55 +02:00
case "followage":
if msgLen <= 2 {
nb.Send(target, "Usage: ()followage [channel] [user]")
return
} else {
commands.Followage(target, cmdParams[1], cmdParams[2], nb)
2021-10-19 22:33:08 +02:00
return
}
2021-10-21 01:43:10 +02:00
2021-10-28 18:15:17 +02:00
case "fox":
commands.RandomFox(target, nb)
return
2021-10-19 23:27:55 +02:00
case "game":
if msgLen == 1 {
nb.Send(target, "Usage: ()game [channel]")
return
} else {
commands.Game(target, cmdParams[1], nb)
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "godoc":
if msgLen == 1 {
nb.Send(target, "Usage: ()godoc [term]")
return
} else {
commands.Godocs(target, message.Message[8:len(message.Message)], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "godocs":
if msgLen == 1 {
nb.Send(target, "Usage: ()godoc [term]")
return
} else {
commands.Godocs(target, message.Message[9:len(message.Message)], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-23 22:11:23 +02:00
case "help":
commands.Help(target, nb)
2021-10-31 14:25:47 +01:00
return
2021-10-23 22:16:58 +02:00
2021-10-28 18:15:17 +02:00
case "join":
if msgLen == 1 || message.User.ID != "31437432" {
nb.Send(target, "You are not allowed to do this")
return
}
db.AddChannel(target, cmdParams[1], nb)
return
//. case "mycolor":
//. commands.Color(message, nb)
//. return
2021-10-28 18:15:17 +02:00
2021-10-25 13:52:09 +02:00
case "nourybot":
2021-10-23 22:15:29 +02:00
commands.Help(target, nb)
2021-10-31 14:25:47 +01:00
return
2021-10-23 22:11:23 +02:00
2021-10-19 23:53:41 +02:00
case "num":
if msgLen == 1 {
commands.RandomNumber(target, nb)
2021-10-31 14:25:47 +01:00
return
2021-10-19 23:53:41 +02:00
} else {
commands.Number(target, cmdParams[1], nb)
2021-10-31 14:25:47 +01:00
return
2021-10-19 23:53:41 +02:00
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "number":
if msgLen == 1 {
commands.RandomNumber(target, nb)
2021-10-31 14:25:47 +01:00
return
2021-10-19 23:53:41 +02:00
} else {
commands.Number(target, cmdParams[1], nb)
2021-10-31 14:25:47 +01:00
return
2021-10-28 18:15:17 +02:00
2021-10-19 23:53:41 +02:00
}
2021-10-26 17:37:45 +02:00
case "osrs":
if msgLen == 1 {
nb.Send(target, "Usage: ()osrs [term]")
return
} else {
commands.Osrs(target, message.Message[7:len(message.Message)], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-28 18:15:17 +02:00
case "part":
if msgLen == 1 || message.User.ID != "31437432" {
nb.Send(target, "You are not allowed to do this")
return
}
db.PartChannel(target, cmdParams[1], nb)
return
2021-10-19 23:53:41 +02:00
case "ping":
commands.Ping(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "pingme":
commands.Pingme(target, message.User.DisplayName, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "preview":
if msgLen == 1 {
nb.Send(target, "Usage: ()preview [channel]")
return
} else {
commands.Thumbnail(target, cmdParams[1], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "profilepicture":
if msgLen == 1 {
nb.Send(target, "Usage: ()profilepicture [user]")
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
commands.ProfilePicture(target, cmdParams[1], nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "pfp":
if msgLen == 1 {
nb.Send(target, "Usage: ()pfp [user]")
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
commands.ProfilePicture(target, cmdParams[1], nb)
return
2021-10-19 23:27:55 +02:00
2021-10-25 13:52:09 +02:00
// case "pyramid":
// if msgLen != 3 {
// nb.Send(target, "Usage: ()pyramid [size] [emote]")
// } else if utils.ElevatedPrivsMessage(message) {
// commands.Pyramid(target, cmdParams[1], cmdParams[2], nb)
// } else {
// nb.Send(target, "Pleb's can't pyramid FeelsBadMan")
// }
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "randomcat":
commands.RandomCat(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "randomdog":
commands.RandomDog(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-20 17:27:00 +02:00
case "randomduck":
commands.RandomDuck(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "randomfox":
commands.RandomFox(target, nb)
return
2021-10-21 01:43:10 +02:00
2021-10-22 17:01:36 +02:00
case "rq":
if msgLen == 1 {
nb.Send(target, "Usage: ()rq [channel] [user]")
return
} else if msgLen == 2 {
commands.RandomQuote(target, target, cmdParams[1], nb)
return
} else {
commands.RandomQuote(target, cmdParams[1], cmdParams[2], nb)
return
}
case "randomquote":
if msgLen == 1 {
nb.Send(target, "Usage: ()randomquote [channel] [user]")
return
} else if msgLen == 2 {
commands.RandomQuote(target, target, cmdParams[1], nb)
return
} else {
commands.RandomQuote(target, cmdParams[1], cmdParams[2], nb)
return
}
2021-10-23 21:59:56 +02:00
2021-10-19 22:58:09 +02:00
case "randomxkcd":
2021-10-19 23:27:55 +02:00
commands.RandomXkcd(target, nb)
2021-10-19 22:58:09 +02:00
return
2021-10-21 01:43:10 +02:00
case "robo":
2021-10-23 19:05:42 +02:00
commands.RoboHash(target, message, nb)
return
2021-10-23 22:15:29 +02:00
case "robohash":
2021-10-23 19:05:42 +02:00
commands.RoboHash(target, message, nb)
return
2021-10-19 23:53:41 +02:00
case "subage":
if msgLen < 3 {
2021-10-23 21:33:22 +02:00
nb.Send(target, "Usage: ()subage [streamer] [user]")
2021-10-19 23:53:41 +02:00
return
} else {
2021-10-23 21:33:22 +02:00
commands.Subage(target, cmdParams[2], cmdParams[1], nb)
2021-10-19 23:53:41 +02:00
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "thumb":
if msgLen == 1 {
2021-10-20 00:02:53 +02:00
nb.Send(target, "Usage: ()thumb [channel]")
2021-10-19 23:53:41 +02:00
return
} else {
commands.Thumbnail(target, cmdParams[1], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "thumbnail":
if msgLen == 1 {
nb.Send(target, "Usage: ()thumbnail [channel]")
return
} else {
commands.Thumbnail(target, cmdParams[1], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "title":
if msgLen == 1 {
commands.Title(target, target, nb)
return
} else {
commands.Title(target, cmdParams[1], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "uptime":
if msgLen == 1 {
commands.Uptime(target, target, nb)
return
} else {
commands.Uptime(target, cmdParams[1], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "uid":
if msgLen == 1 {
nb.Send(target, "Usage: ()uid [username]")
return
} else {
commands.Userid(target, cmdParams[1], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 23:53:41 +02:00
case "userid":
if msgLen == 1 {
nb.Send(target, "Usage: ()userid [username]")
return
} else {
commands.Userid(target, cmdParams[1], nb)
return
}
2021-10-21 01:43:10 +02:00
2021-10-19 22:58:09 +02:00
case "weather":
if msgLen == 1 {
2021-10-19 23:27:55 +02:00
nb.Send(target, "Usage: ()weather [location]")
2021-10-19 22:58:09 +02:00
return
} else {
2021-10-19 23:27:55 +02:00
commands.Weather(target, message.Message[9:len(message.Message)], nb)
2021-10-19 22:58:09 +02:00
return
}
2021-10-21 01:43:10 +02:00
2021-10-29 21:55:19 +02:00
case "whois":
if msgLen == 1 {
nb.Send(target, "Usage: ()whois [user]")
return
} else {
commands.Whois(target, cmdParams[1], nb)
return
}
2021-10-19 23:53:41 +02:00
case "xd":
commands.Xd(target, nb)
2021-10-21 01:43:10 +02:00
return
2021-10-19 22:58:09 +02:00
case "xkcd":
2021-10-19 23:27:55 +02:00
commands.Xkcd(target, nb)
2021-10-19 22:58:09 +02:00
return
2021-11-06 21:03:03 +01:00
2021-12-13 20:53:24 +01:00
// Basically just personal commands for my own channel from here on.
2021-11-06 21:35:48 +01:00
case "arch":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
2021-11-06 21:35:48 +01:00
personal.Arch(target, nb)
return
} else {
return
}
case "arch2":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
2021-11-06 21:35:48 +01:00
personal.ArchTwo(target, nb)
return
} else {
return
}
2021-11-06 21:18:38 +01:00
case "farm":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Farm(target, nb)
2021-11-06 21:18:38 +01:00
return
} else {
return
}
case "justinfan":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Justinfan(target, nb)
2021-11-06 21:18:38 +01:00
return
} else {
return
}
case "farming":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Farm(target, nb)
2021-11-06 21:18:38 +01:00
return
} else {
return
}
2021-11-06 21:03:03 +01:00
case "rave":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Rave(target, nb)
return
} else {
return
}
case "repeat":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Xset(target, nb)
2021-11-06 21:03:03 +01:00
return
} else {
return
}
2021-11-06 21:18:38 +01:00
case "streamlink":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Streamlink(target, nb)
2021-11-06 21:18:38 +01:00
return
} else {
return
}
case "streamlinkconfig":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Streamlink(target, nb)
2021-11-06 21:18:38 +01:00
return
} else {
return
}
2021-11-06 21:03:03 +01:00
case "xset":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
personal.Xset(target, nb)
2021-11-06 21:03:03 +01:00
return
} else {
return
}
2021-11-06 21:35:48 +01:00
case "zneix":
2021-12-13 17:55:48 +01:00
if target == "nouryxd" || target == "nourybot" {
2021-11-06 21:35:48 +01:00
personal.Zneix(target, nb)
return
} else {
return
}
2021-10-19 22:33:08 +02:00
}
2021-10-14 00:19:35 +02:00
}