From 956b1a8614772ef19830f6e065bc3e9ec42866a1 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Sat, 4 Jun 2022 02:40:43 +0200 Subject: [PATCH] add privatemessage base --- cmd/bot/main.go | 4 ++++ cmd/bot/privatemessage.go | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cmd/bot/privatemessage.go diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 7f0b77b..4d767d3 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -44,6 +44,10 @@ func main() { logger: logger, } + app.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) { + app.handlePrivateMessage(message) + }) + app.twitchClient.Join("nourylul") app.twitchClient.Join("nourybot") diff --git a/cmd/bot/privatemessage.go b/cmd/bot/privatemessage.go new file mode 100644 index 0000000..1594e2f --- /dev/null +++ b/cmd/bot/privatemessage.go @@ -0,0 +1,27 @@ +package main + +import "github.com/gempir/go-twitch-irc/v3" + +func (app *application) handlePrivateMessage(message twitch.PrivateMessage) { + // 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. + if roomId == "" { + app.logger.Print("Missing room-id in message tag ", roomId) + return + } + + if len(message.Message) >= 2 { + if message.Message[:2] == "()" { + // TODO: Command Handling + app.logger.Println("[Command detected]: ", message.Message) + return + } + } + + // Message was no command so we just print it. + app.logger.Printf("[#%s]:%s: %s", message.Channel, message.User.DisplayName, message.Message) + +}