mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
Compare commits
2 commits
eb02858280
...
e1434eb403
Author | SHA1 | Date | |
---|---|---|---|
e1434eb403 | |||
fa9f5591f6 |
3 changed files with 35 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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
28
irc.go
|
@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue