2020-12-21 00:32:39 +00:00
|
|
|
package main
|
|
|
|
|
2022-02-08 18:58:19 +00:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2022-11-02 21:38:14 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/v3/plugins"
|
2022-02-08 18:58:19 +00:00
|
|
|
)
|
|
|
|
|
2020-12-21 00:32:39 +00:00
|
|
|
func ptrStr(s string) *string { return &s }
|
|
|
|
|
2022-02-08 18:58:19 +00:00
|
|
|
var (
|
|
|
|
registeredEventHandlers []plugins.EventHandlerFunc
|
|
|
|
registeredEventHandlersLock sync.Mutex
|
|
|
|
)
|
|
|
|
|
2020-12-21 00:32:39 +00:00
|
|
|
var (
|
2023-10-21 14:43:44 +00:00
|
|
|
eventTypeAdBreakBegin = ptrStr("adbreak_begin")
|
2022-04-01 00:02:14 +00:00
|
|
|
eventTypeAnnouncement = ptrStr("announcement")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeBan = ptrStr("ban")
|
|
|
|
eventTypeBits = ptrStr("bits")
|
2022-03-31 11:20:02 +00:00
|
|
|
eventTypeCustom = ptrStr("custom")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeChannelPointRedeem = ptrStr("channelpoint_redeem")
|
|
|
|
eventTypeClearChat = ptrStr("clearchat")
|
2022-02-11 19:10:19 +00:00
|
|
|
eventTypeDelete = ptrStr("delete")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeFollow = ptrStr("follow")
|
|
|
|
eventTypeGiftPaidUpgrade = ptrStr("giftpaidupgrade")
|
2024-02-29 18:00:44 +00:00
|
|
|
eventTypeHypetrainBegin = ptrStr("hypetrain_begin")
|
|
|
|
eventTypeHypetrainEnd = ptrStr("hypetrain_end")
|
|
|
|
eventTypeHypetrainProgress = ptrStr("hypetrain_progress")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeJoin = ptrStr("join")
|
2024-02-15 17:25:16 +00:00
|
|
|
eventKoFiDonation = ptrStr("kofi_donation")
|
2022-10-29 13:16:30 +00:00
|
|
|
eventTypeOutboundRaid = ptrStr("outbound_raid")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypePart = ptrStr("part")
|
|
|
|
eventTypePermit = ptrStr("permit")
|
2023-05-21 12:59:06 +00:00
|
|
|
eventTypePollBegin = ptrStr("poll_begin")
|
|
|
|
eventTypePollEnd = ptrStr("poll_end")
|
|
|
|
eventTypePollProgress = ptrStr("poll_progress")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeRaid = ptrStr("raid")
|
|
|
|
eventTypeResub = ptrStr("resub")
|
2023-03-21 09:51:34 +00:00
|
|
|
eventTypeShoutoutCreated = ptrStr("shoutout_created")
|
2023-02-11 22:00:15 +00:00
|
|
|
eventTypeShoutoutReceived = ptrStr("shoutout_received")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeSubgift = ptrStr("subgift")
|
|
|
|
eventTypeSubmysterygift = ptrStr("submysterygift")
|
|
|
|
eventTypeSub = ptrStr("sub")
|
|
|
|
eventTypeTimeout = ptrStr("timeout")
|
2023-12-24 14:23:17 +00:00
|
|
|
eventTypeWatchStreak = ptrStr("watch_streak")
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeWhisper = ptrStr("whisper")
|
2021-09-02 15:09:30 +00:00
|
|
|
|
|
|
|
eventTypeTwitchCategoryUpdate = ptrStr("category_update")
|
|
|
|
eventTypeTwitchStreamOffline = ptrStr("stream_offline")
|
|
|
|
eventTypeTwitchStreamOnline = ptrStr("stream_online")
|
|
|
|
eventTypeTwitchTitleUpdate = ptrStr("title_update")
|
2021-09-22 13:36:45 +00:00
|
|
|
|
|
|
|
knownEvents = []*string{
|
2023-10-21 14:43:44 +00:00
|
|
|
eventTypeAdBreakBegin,
|
2022-04-01 00:02:14 +00:00
|
|
|
eventTypeAnnouncement,
|
2021-11-10 22:23:57 +00:00
|
|
|
eventTypeBan,
|
|
|
|
eventTypeBits,
|
2022-03-31 11:20:02 +00:00
|
|
|
eventTypeCustom,
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeChannelPointRedeem,
|
2021-11-10 22:23:57 +00:00
|
|
|
eventTypeClearChat,
|
2022-02-11 19:10:19 +00:00
|
|
|
eventTypeDelete,
|
2021-12-24 19:23:38 +00:00
|
|
|
eventTypeFollow,
|
2021-11-19 18:54:53 +00:00
|
|
|
eventTypeGiftPaidUpgrade,
|
2024-03-06 16:50:11 +00:00
|
|
|
eventTypeHypetrainBegin,
|
|
|
|
eventTypeHypetrainEnd,
|
|
|
|
eventTypeHypetrainProgress,
|
2021-11-19 18:54:53 +00:00
|
|
|
eventTypeJoin,
|
2024-02-15 17:25:16 +00:00
|
|
|
eventKoFiDonation,
|
2022-10-29 13:16:30 +00:00
|
|
|
eventTypeOutboundRaid,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypePart,
|
|
|
|
eventTypePermit,
|
2023-05-21 12:59:06 +00:00
|
|
|
eventTypePollBegin,
|
|
|
|
eventTypePollEnd,
|
|
|
|
eventTypePollProgress,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypeRaid,
|
|
|
|
eventTypeResub,
|
2023-08-13 23:18:45 +00:00
|
|
|
eventTypeShoutoutCreated,
|
2023-02-11 22:00:15 +00:00
|
|
|
eventTypeShoutoutReceived,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypeSub,
|
|
|
|
eventTypeSubgift,
|
2021-10-16 12:06:25 +00:00
|
|
|
eventTypeSubmysterygift,
|
2021-11-10 22:23:57 +00:00
|
|
|
eventTypeTimeout,
|
2023-12-24 14:23:17 +00:00
|
|
|
eventTypeWatchStreak,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypeWhisper,
|
|
|
|
|
|
|
|
eventTypeTwitchCategoryUpdate,
|
|
|
|
eventTypeTwitchStreamOffline,
|
|
|
|
eventTypeTwitchStreamOnline,
|
|
|
|
eventTypeTwitchTitleUpdate,
|
|
|
|
}
|
2020-12-21 00:32:39 +00:00
|
|
|
)
|
2022-02-08 18:58:19 +00:00
|
|
|
|
|
|
|
func notifyEventHandlers(event string, eventData *plugins.FieldCollection) {
|
|
|
|
registeredEventHandlersLock.Lock()
|
|
|
|
defer registeredEventHandlersLock.Unlock()
|
|
|
|
|
|
|
|
for _, fn := range registeredEventHandlers {
|
|
|
|
if err := fn(event, eventData); err != nil {
|
|
|
|
log.WithError(err).Error("EventHandler caused error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerEventHandlers(eh plugins.EventHandlerFunc) error {
|
|
|
|
registeredEventHandlersLock.Lock()
|
|
|
|
defer registeredEventHandlersLock.Unlock()
|
|
|
|
|
|
|
|
registeredEventHandlers = append(registeredEventHandlers, eh)
|
|
|
|
return nil
|
|
|
|
}
|