From 0b8196b12792b25f8d030dc9924d97bc176dd167 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 21 Jul 2023 23:25:20 +0200 Subject: [PATCH] [core] Add support for `hype_chat` event Signed-off-by: Knut Ahlers --- events.go | 2 ++ irc.go | 18 ++++++++++++++++++ wiki/Events.md | 15 +++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/events.go b/events.go index 8cf81aa..088fe37 100644 --- a/events.go +++ b/events.go @@ -25,6 +25,7 @@ var ( eventTypeDelete = ptrStr("delete") eventTypeFollow = ptrStr("follow") eventTypeGiftPaidUpgrade = ptrStr("giftpaidupgrade") + eventTypeHypeChat = ptrStr("hype_chat") eventTypeJoin = ptrStr("join") eventTypeOutboundRaid = ptrStr("outbound_raid") eventTypePart = ptrStr("part") @@ -57,6 +58,7 @@ var ( eventTypeDelete, eventTypeFollow, eventTypeGiftPaidUpgrade, + eventTypeHypeChat, eventTypeJoin, eventTypeOutboundRaid, eventTypePart, diff --git a/irc.go b/irc.go index b901b20..5ef74bd 100644 --- a/irc.go +++ b/irc.go @@ -3,6 +3,7 @@ package main import ( "crypto/tls" "fmt" + "math" "strconv" "strings" "sync" @@ -354,6 +355,23 @@ func (i ircHandler) handleTwitchPrivmsg(m *irc.Message) { go handleMessage(i.c, m, eventTypeBits, fields) } + if amount := i.tagToNumeric(m, "pinned-chat-paid-amount", 0); amount > 0 { + fields := plugins.FieldCollectionFromData(map[string]any{ + "amount": float64(amount) / math.Pow10(int(i.tagToNumeric(m, "pinned-chat-paid-exponent", 0))), + "currency": m.Tags["pinned-chat-paid-currency"], + eventFieldChannel: i.getChannel(m), + eventFieldUserID: m.Tags["user-id"], + eventFieldUserName: m.User, + "is_system_message": m.Tags["pinned-chat-paid-is-system-message"] == "1", + "level": m.Tags["pinned-chat-paid-level"], + "message": m.Trailing(), + }) + + log.WithFields(log.Fields(fields.Data())).Info("User used hype-chat message") + + go handleMessage(i.c, m, eventTypeHypeChat, fields) + } + go handleMessage(i.c, m, nil, nil) } diff --git a/wiki/Events.md b/wiki/Events.md index 3568020..59c317f 100644 --- a/wiki/Events.md +++ b/wiki/Events.md @@ -89,6 +89,21 @@ Fields: - `gifter` - The login-name of the user who gifted the subscription - `username` - The login-name of the user who upgraded their subscription +## `hype_chat` + +User used the Twitch "Hype Chat" to pin a message to the chat. + +Fields: + +- `amount` - Amount of money the user spent (float64, i.e. `1.2` when they used 1.20 EUR) +- `channel` - The channel the event occurred in +- `currency` - [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217#List_of_ISO_4217_currency_codes) alphabetic currency code +- `is_system_message` - Set to `true` if the user left no message and the message was system-generated +- `level` - `ONE` to `TEN`, uppercase number-words +- `messge` - The message the user sent (or the system generated) +- `user_id` - ID of the user +- `user` - The login-name of the user who sent the message + ## `join` User joined the channel-chat. This is **NOT** an indicator they are viewing, the event is **NOT** reliably sent when the user really joined the chat. The event will be sent with some delay after they join the chat and is sometimes repeated multiple times during their stay. So **DO NOT** use this to greet users!