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 (
|
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")
|
|
|
|
eventTypeHost = ptrStr("host")
|
|
|
|
eventTypeJoin = ptrStr("join")
|
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")
|
|
|
|
eventTypeRaid = ptrStr("raid")
|
|
|
|
eventTypeResub = ptrStr("resub")
|
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")
|
|
|
|
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{
|
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,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypeHost,
|
2021-11-19 18:54:53 +00:00
|
|
|
eventTypeJoin,
|
2022-10-29 13:16:30 +00:00
|
|
|
eventTypeOutboundRaid,
|
2021-09-22 13:36:45 +00:00
|
|
|
eventTypePart,
|
|
|
|
eventTypePermit,
|
|
|
|
eventTypeRaid,
|
|
|
|
eventTypeResub,
|
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,
|
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
|
|
|
|
}
|