diff --git a/cmd/main.go b/cmd/main.go index 88376ec..47cabbc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -35,4 +35,7 @@ func main() { handlers.PrivateMessage(message, nb) }) + + nb.TwitchClient.Join("nourybot") + nb.TwitchClient.Connect() } diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 5e1dd1b..b891f5c 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -1,6 +1,8 @@ package handlers import ( + "strings" + "github.com/gempir/go-twitch-irc/v2" "github.com/lyx0/nourybot/cmd/bot" "github.com/sirupsen/logrus" @@ -9,6 +11,30 @@ import ( func Command(message twitch.PrivateMessage, nb *bot.Bot) { logrus.Info("fn Command") - nb.Send("nourybot", "xd") + // 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 + } + } } diff --git a/pkg/handlers/privatemessage.go b/pkg/handlers/privatemessage.go index c18cb64..81670c5 100644 --- a/pkg/handlers/privatemessage.go +++ b/pkg/handlers/privatemessage.go @@ -11,7 +11,7 @@ import ( // PrivateMessage is a command or not and passes it on accordingly. // Typical twitch message tags https://paste.ivr.fi/nopiradodo.lua func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) { - log.Info("fn HandlePrivateMessage") + log.Info("fn PrivateMessage") // log.Info(message) // roomId is the Twitch UserID of the channel the message @@ -24,9 +24,6 @@ func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) { return } - // Message was sent from the Bot. Don't act on it - // so that we don't repeat ourself. - // Since our command prefix is () ignore every message // that is less than 2 if len(message.Message) >= 2 {