mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
move basic message routing into main function
This commit is contained in:
parent
2f6657bdff
commit
28b318dc92
2 changed files with 33 additions and 51 deletions
|
@ -57,12 +57,43 @@ func main() {
|
||||||
|
|
||||||
// Received a PrivateMessage (normal chat message).
|
// Received a PrivateMessage (normal chat message).
|
||||||
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
||||||
app.handlePrivateMessage(message)
|
// app.Logger.Infow("Private Message received",
|
||||||
|
// // "message", message,
|
||||||
|
// "message.Channel", message.Channel,
|
||||||
|
// "message.User", message.User.DisplayName,
|
||||||
|
// "message.Message", message.Message,
|
||||||
|
// )
|
||||||
|
|
||||||
|
// roomId is the Twitch UserID of the channel the message originated from.
|
||||||
|
// If there is no roomId something went really wrong.
|
||||||
|
roomId := message.Tags["room-id"]
|
||||||
|
if roomId == "" {
|
||||||
|
app.Logger.Errorw("Missing room-id in message tag",
|
||||||
|
"roomId", roomId,
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message was shorter than our prefix is therefore it's irrelevant for us.
|
||||||
|
if len(message.Message) >= 2 {
|
||||||
|
// Check if the first 2 characters of the mesage were our prefix.
|
||||||
|
if message.Message[:2] == "()" {
|
||||||
|
app.handleCommand(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Received a WhisperMessage (Twitch DM).
|
// Received a WhisperMessage (Twitch DM).
|
||||||
app.TwitchClient.OnWhisperMessage(func(message twitch.WhisperMessage) {
|
app.TwitchClient.OnWhisperMessage(func(message twitch.WhisperMessage) {
|
||||||
app.handleWhisperMessage(message)
|
// Print the whisper message for now.
|
||||||
|
app.Logger.Infow("Whisper Message received",
|
||||||
|
"message", message,
|
||||||
|
"message.User.DisplayName", message.User.DisplayName,
|
||||||
|
"message.Message", message.Message,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Successfully connected to Twitch
|
// Successfully connected to Twitch
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gempir/go-twitch-irc/v3"
|
|
||||||
"go.uber.org/zap"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) {
|
|
||||||
sugar := zap.NewExample().Sugar()
|
|
||||||
defer sugar.Sync()
|
|
||||||
|
|
||||||
// roomId is the Twitch UserID of the channel the message originated from.
|
|
||||||
// If there is no roomId something went really wrong.
|
|
||||||
roomId := message.Tags["room-id"]
|
|
||||||
if roomId == "" {
|
|
||||||
app.Logger.Errorw("Missing room-id in message tag",
|
|
||||||
"roomId", roomId,
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Message was shorter than our prefix is therefore it's irrelevant for us.
|
|
||||||
if len(message.Message) >= 2 {
|
|
||||||
// Strip the `()` prefix
|
|
||||||
if message.Message[:2] == "()" {
|
|
||||||
app.handleCommand(message)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// app.Logger.Infow("Private Message received",
|
|
||||||
// // "message", message,
|
|
||||||
// "message.Channel", message.Channel,
|
|
||||||
// "message.User", message.User.DisplayName,
|
|
||||||
// "message.Message", message.Message,
|
|
||||||
// )
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
|
Loading…
Reference in a new issue