2021-10-14 00:45:32 +02:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gempir/go-twitch-irc/v2"
|
2021-10-19 22:25:47 +02:00
|
|
|
"github.com/lyx0/nourybot/cmd/bot"
|
2021-10-14 00:45:32 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2021-10-21 00:07:18 +02:00
|
|
|
// PrivateMessage checks messages for correctness and forwards
|
|
|
|
// commands to the command handler.
|
2021-10-19 22:25:47 +02:00
|
|
|
func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) {
|
2021-10-22 22:24:13 +02:00
|
|
|
// log.Info("fn PrivateMessage")
|
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
|
|
|
|
}
|
|
|
|
|
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] == "()" {
|
2021-10-19 22:25:47 +02:00
|
|
|
Command(message, nb)
|
2021-10-14 00:55:07 +02:00
|
|
|
return
|
2021-10-14 00:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-14 15:14:38 +02:00
|
|
|
// Message was no command
|
|
|
|
// log.Info(message)
|
2021-10-14 00:55:07 +02:00
|
|
|
|
2021-10-14 00:45:32 +02:00
|
|
|
}
|