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"
|
|
|
|
|
|
|
|
"github.com/Luzifer/twitch-bot/plugins"
|
|
|
|
)
|
|
|
|
|
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 (
|
2021-12-24 23:47:40 +00:00
|
|
|
eventTypeBan = ptrStr("ban")
|
|
|
|
eventTypeBits = ptrStr("bits")
|
|
|
|
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")
|
|
|
|
eventTypeHost = ptrStr("host")
|
|
|
|
eventTypeJoin = ptrStr("join")
|
|
|
|
eventTypePart = ptrStr("part")
|
|
|
|
eventTypePermit = ptrStr("permit")
|
|
|
|
eventTypeRaid = ptrStr("raid")
|
|
|
|
eventTypeResub = ptrStr("resub")
|
|
|
|
eventTypeSubgift = ptrStr("subgift")
|
|
|
|
eventTypeSubmysterygift = ptrStr("submysterygift")
|
|
|
|
eventTypeSub = ptrStr("sub")
|
|
|
|
eventTypeTimeout = ptrStr("timeout")
|
|
|
|
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{
|
2021-11-10 22:23:57 +00:00
|
|
|
eventTypeBan,
|
|
|
|
eventTypeBits,
|
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,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypeHost,
|
2021-11-19 18:54:53 +00:00
|
|
|
eventTypeJoin,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypePart,
|
|
|
|
eventTypePermit,
|
|
|
|
eventTypeRaid,
|
|
|
|
eventTypeResub,
|
|
|
|
eventTypeSub,
|
|
|
|
eventTypeSubgift,
|
2021-10-16 12:06:25 +00:00
|
|
|
eventTypeSubmysterygift,
|
2021-11-10 22:23:57 +00:00
|
|
|
eventTypeTimeout,
|
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
|
|
|
|
}
|