mirror-nourybot/cmd/bot/message.go

51 lines
1.3 KiB
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-08 23:12:50 +02:00
handleCommand(message, app)
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
}
func (app *Application) handleWhisperMessage(message twitch.WhisperMessage) {
// Print the whisper message for now.
// TODO: Implement a basic whisper handler.
app.Logger.Infow("Whisper Message received",
"message", message,
"message.User.DisplayName", message.User.DisplayName,
"message.Message", message.Message,
)
}