2021-10-14 01:36:42 +02:00
|
|
|
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))
|
|
|
|
|
2021-10-19 23:27:55 +02:00
|
|
|
// target channel
|
|
|
|
target := message.Channel
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
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-19 23:27:55 +02:00
|
|
|
case "bttvemotes":
|
|
|
|
commands.BttvEmotes(target, nb)
|
|
|
|
return
|
|
|
|
case "cf":
|
|
|
|
commands.Coinflip(target, nb)
|
|
|
|
return
|
|
|
|
case "coin":
|
|
|
|
commands.Coinflip(target, nb)
|
|
|
|
return
|
|
|
|
case "coinflip":
|
|
|
|
commands.Coinflip(target, nb)
|
|
|
|
return
|
|
|
|
case "color":
|
|
|
|
commands.Color(message, nb)
|
|
|
|
return
|
|
|
|
case "mycolor":
|
|
|
|
commands.Color(message, nb)
|
|
|
|
return
|
2021-10-19 22:33:08 +02:00
|
|
|
case "echo":
|
2021-10-19 23:27:55 +02:00
|
|
|
commands.Echo(target, message.Message[7:len(message.Message)], nb)
|
|
|
|
return
|
|
|
|
case "8ball":
|
|
|
|
commands.EightBall(target, nb)
|
|
|
|
return
|
|
|
|
case "ffzemotes":
|
|
|
|
commands.FfzEmotes(target, nb)
|
|
|
|
return
|
|
|
|
|
|
|
|
case "fill":
|
|
|
|
if msgLen == 1 {
|
|
|
|
nb.Send(target, "Usage: ()fill [emote]")
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Fill(target, message.Message[7:len(message.Message)], nb)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "firstline":
|
|
|
|
if msgLen == 1 {
|
|
|
|
nb.Send(target, "Usage: ()firstline [channel] [user]")
|
|
|
|
return
|
|
|
|
} else if msgLen == 2 {
|
|
|
|
commands.Firstline(target, message.Channel, cmdParams[1], nb)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Firstline(target, cmdParams[1], cmdParams[2], nb)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "fl":
|
|
|
|
if msgLen == 1 {
|
|
|
|
nb.Send(target, "Usage: ()firstline [channel] [user]")
|
|
|
|
return
|
|
|
|
} else if msgLen == 2 {
|
|
|
|
commands.Firstline(target, message.Channel, cmdParams[1], nb)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
commands.Firstline(target, cmdParams[1], cmdParams[2], nb)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
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-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-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-19 22:39:25 +02:00
|
|
|
case "ping":
|
2021-10-19 23:27:55 +02:00
|
|
|
commands.Ping(target, nb)
|
2021-10-19 22:58:09 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
case "xkcd":
|
2021-10-19 23:27:55 +02:00
|
|
|
commands.Xkcd(target, nb)
|
2021-10-19 22:58:09 +02:00
|
|
|
return
|
2021-10-19 22:33:08 +02:00
|
|
|
}
|
2021-10-15 18:35:16 +02:00
|
|
|
|
2021-10-14 00:19:35 +02:00
|
|
|
}
|