2021-10-14 00:45:32 +02:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gempir/go-twitch-irc/v2"
|
|
|
|
"github.com/lyx0/nourybot/pkg/commands"
|
2021-10-14 00:55:07 +02:00
|
|
|
"github.com/lyx0/nourybot/pkg/config"
|
2021-10-14 00:45:32 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HandleTwitchMessage takes in a twitch.Privatemessage and
|
|
|
|
// *twitch.Client and has the logic to decide if the provided
|
|
|
|
// PrivateMessage is a command or not and passes it on accordingly.
|
|
|
|
// Typical twitch message tags https://paste.ivr.fi/nopiradodo.lua
|
2021-10-14 00:55:07 +02:00
|
|
|
func HandleTwitchMessage(message twitch.PrivateMessage, client *twitch.Client, cfg *config.Config) {
|
2021-10-14 00:45:32 +02:00
|
|
|
log.Info("fn HandleTwitchMessage")
|
2021-10-14 00:55:07 +02:00
|
|
|
// log.Info(message)
|
2021-10-14 00:45:32 +02:00
|
|
|
|
|
|
|
// roomId is the Twitch UserID of the channel the message
|
|
|
|
// was sent in.
|
|
|
|
roomId := message.Tags["room-id"]
|
|
|
|
|
|
|
|
// The message has no room-id so something went wrong.
|
|
|
|
if roomId == "" {
|
|
|
|
log.Errorf("Missing room-id in message tag", roomId)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message was sent from the Bot. Don't act on it
|
|
|
|
// so that we don't repeat ourself.
|
2021-10-14 00:55:07 +02:00
|
|
|
botUserId := cfg.BotUserId
|
|
|
|
if message.Tags["user-id"] == botUserId {
|
2021-10-14 00:45:32 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-14 00:55:07 +02:00
|
|
|
// Since our command prefix is () ignore every message
|
|
|
|
// that is less than 2
|
2021-10-14 00:45:32 +02:00
|
|
|
if len(message.Message) >= 2 {
|
2021-10-14 00:55:07 +02:00
|
|
|
|
|
|
|
// Message starts with (), pass it on to
|
|
|
|
// the command handler.
|
2021-10-14 00:45:32 +02:00
|
|
|
if message.Message[:2] == "()" {
|
|
|
|
commands.HandleCommand(message, client)
|
2021-10-14 00:55:07 +02:00
|
|
|
return
|
2021-10-14 00:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-14 00:55:07 +02:00
|
|
|
// Message was no command, just log it for now
|
|
|
|
// TODO: Add actual message logger
|
|
|
|
log.Info(message)
|
|
|
|
|
2021-10-14 00:45:32 +02:00
|
|
|
}
|