diff --git a/cmd/bot/command.go b/cmd/bot/command.go index dcb43b4..d289fd9 100644 --- a/cmd/bot/command.go +++ b/cmd/bot/command.go @@ -13,14 +13,9 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) { sugar := zap.NewExample().Sugar() defer sugar.Sync() - //sugar.Infow("Command received", - // "message", message) - // commandName is the actual name of the command without the prefix. // e.g. `()ping` would be `ping`. commandName := strings.ToLower(strings.SplitN(message.Message, " ", 3)[0][2:]) - sugar.Infow("[handleCommand]", - "commandName", commandName) // cmdParams are additional command parameters. // e.g. `()weather san antonio` @@ -35,13 +30,20 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) { // msgLen is the amount of words in a message without the prefix. // Useful to check if enough cmdParams are provided. msgLen := len(strings.SplitN(message.Message, " ", -2)) - // sugar.Infow("handleCommand", - // "msgLen:", msgLen) // target is the channelname the message originated from and // where we are responding. target := message.Channel + sugar.Infow("Command received", + // "message", message, + "message.Message", message.Message, + "target", target, + "commandName", commandName, + "cmdParams", cmdParams, + "msgLen", msgLen, + ) + switch commandName { case "": if msgLen == 1 { diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 93bbc30..d70ded8 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -24,10 +24,10 @@ func main() { TwitchClient: tc, Logger: sugar, } + // Received a PrivateMessage (normal chat message), pass it to // the handler who checks for further action. app.TwitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) { - //app.Logger.Infof("%s", message) app.handlePrivateMessage(message) }) diff --git a/cmd/bot/privatemessage.go b/cmd/bot/privatemessage.go index 237ed6c..5cf0ad5 100644 --- a/cmd/bot/privatemessage.go +++ b/cmd/bot/privatemessage.go @@ -8,8 +8,8 @@ import ( 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. + + // roomId is the Twitch UserID of the channel the message originated from. roomId := message.Tags["room-id"] // If there is no roomId something went wrong. @@ -19,11 +19,9 @@ func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) { return } + // Message was shorter than our prefix is therefore it's irrelevant for us. if len(message.Message) >= 2 { if message.Message[:2] == "()" { - // app.Logger.Infow("handlePrivateMessage", - // "message.Message", message.Message) - handleCommand(message, app.TwitchClient) return } @@ -31,8 +29,10 @@ func (app *Application) handlePrivateMessage(message twitch.PrivateMessage) { // Message was no command so we just print it. app.Logger.Infow("Private Message received", + "message", message, "message.Channel", message.Channel, "message.User", message.User.DisplayName, - "message.Message", message.Message) + "message.Message", message.Message, + ) } diff --git a/cmd/bot/whispermessage.go b/cmd/bot/whispermessage.go index 8a255bc..ffb0076 100644 --- a/cmd/bot/whispermessage.go +++ b/cmd/bot/whispermessage.go @@ -6,6 +6,7 @@ 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) }