Compare commits

..

2 commits

Author SHA1 Message Date
e1434eb403
[core] Add support for watch_streak event
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2023-12-24 15:32:48 +01:00
fa9f5591f6
[overlays] Fix: Do not spam logs with errors when overlay reloaded
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2023-12-24 14:40:41 +01:00
3 changed files with 35 additions and 9 deletions

View file

@ -42,6 +42,7 @@ var (
eventTypeSubmysterygift = ptrStr("submysterygift")
eventTypeSub = ptrStr("sub")
eventTypeTimeout = ptrStr("timeout")
eventTypeWatchStreak = ptrStr("watch_streak")
eventTypeWhisper = ptrStr("whisper")
eventTypeTwitchCategoryUpdate = ptrStr("category_update")
@ -76,6 +77,7 @@ var (
eventTypeSubgift,
eventTypeSubmysterygift,
eventTypeTimeout,
eventTypeWatchStreak,
eventTypeWhisper,
eventTypeTwitchCategoryUpdate,

View file

@ -315,10 +315,18 @@ func handleSocketSubscription(w http.ResponseWriter, r *http.Request) {
return
case err := <-errC:
if err != nil {
logger.WithError(err).Error("Message processing caused error")
var cErr *websocket.CloseError
switch {
case err == nil:
// We use nil-error to close the connection
case errors.As(err, &cErr) && websocket.IsCloseError(cErr, websocket.CloseNormalClosure, websocket.CloseGoingAway):
// We don't need to log when the remote closes the websocket gracefully
default:
logger.WithError(err).Error("message processing caused error")
}
return // We use nil-error to close the connection
return // All errors need to quit this function
case msg := <-sendMsgC:
if !isAuthorized {

28
irc.go
View file

@ -378,6 +378,7 @@ func (i ircHandler) handleTwitchPrivmsg(m *irc.Message) {
go handleMessage(i.c, m, nil, nil)
}
//nolint:funlen
func (i ircHandler) handleTwitchUsernotice(m *irc.Message) {
log.WithFields(log.Fields{
eventFieldChannel: i.getChannel(m),
@ -391,6 +392,12 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) {
eventFieldUserID: m.Tags["user-id"],
})
message := m.Trailing()
if message == i.getChannel(m) {
// If no message is given, Trailing yields the channel name
message = ""
}
switch m.Tags["msg-id"] {
case "":
// Notices SHOULD have msg-id tags...
@ -423,12 +430,6 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) {
go handleMessage(i.c, m, eventTypeRaid, evtData)
case "resub":
message := m.Trailing()
if message == i.getChannel(m) {
// If no message is given, Trailing yields the channel name
message = ""
}
evtData.SetFromData(map[string]interface{}{
"from": m.Tags["login"],
"message": message,
@ -478,6 +479,21 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) {
go handleMessage(i.c, m, eventTypeSubmysterygift, evtData)
case "viewermilestone":
switch m.Tags["msg-param-category"] {
case "watch-streak":
evtData.SetFromData(map[string]any{
"message": message,
"streak": i.tagToNumeric(m, "msg-param-value", 0),
})
log.WithFields(log.Fields(evtData.Data())).Info("User shared a watch-streak")
go handleMessage(i.c, m, eventTypeWatchStreak, evtData)
default:
log.WithField("category", m.Tags["msg-param-category"]).Debug("found unhandled viewermilestone category")
}
}
}