mirror-nourybot/cmd/bot/privatemessage.go

41 lines
973 B
Go
Raw Normal View History

2022-08-07 01:34:31 +02:00
package main
2022-06-21 00:31:17 +02:00
2022-08-07 03:09:09 +02:00
import (
"github.com/gempir/go-twitch-irc/v3"
"go.uber.org/zap"
)
2022-06-21 00:31:17 +02:00
2022-08-07 01:34:31 +02:00
func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) {
2022-08-07 03:09:09 +02:00
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
2022-08-07 03:17:29 +02:00
// roomId is the Twitch UserID of the channel the message originated from.
2022-08-07 04:35:03 +02:00
// If there is no roomId something went really wrong.
2022-06-21 00:31:17 +02:00
roomId := message.Tags["room-id"]
if roomId == "" {
2022-08-07 04:35:03 +02:00
app.Logger.Errorw("Missing room-id in message tag",
"roomId", roomId,
)
2022-06-21 00:31:17 +02:00
return
}
2022-08-07 03:17:29 +02:00
// Message was shorter than our prefix is therefore it's irrelevant for us.
2022-06-21 00:31:17 +02:00
if len(message.Message) >= 2 {
2022-08-07 04:35:03 +02:00
// Strip the `()` prefix
2022-06-21 00:31:17 +02:00
if message.Message[:2] == "()" {
2022-08-07 02:27:40 +02:00
handleCommand(message, app.TwitchClient)
2022-06-21 00:31:17 +02:00
return
}
}
// Message was no command so we just print it.
2022-08-07 03:09:09 +02:00
app.Logger.Infow("Private Message received",
2022-08-07 04:35:03 +02:00
// "message", message,
2022-08-07 03:09:09 +02:00
"message.Channel", message.Channel,
"message.User", message.User.DisplayName,
2022-08-07 03:17:29 +02:00
"message.Message", message.Message,
)
2022-06-21 00:31:17 +02:00
}