mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
[core] Add "follow" event using EventSub
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
246bb2811d
commit
f70382876a
4 changed files with 41 additions and 0 deletions
|
@ -6,6 +6,7 @@ var (
|
||||||
eventTypeBan = ptrStr("ban")
|
eventTypeBan = ptrStr("ban")
|
||||||
eventTypeBits = ptrStr("bits")
|
eventTypeBits = ptrStr("bits")
|
||||||
eventTypeClearChat = ptrStr("clearchat")
|
eventTypeClearChat = ptrStr("clearchat")
|
||||||
|
eventTypeFollow = ptrStr("follow")
|
||||||
eventTypeGiftPaidUpgrade = ptrStr("giftpaidupgrade")
|
eventTypeGiftPaidUpgrade = ptrStr("giftpaidupgrade")
|
||||||
eventTypeHost = ptrStr("host")
|
eventTypeHost = ptrStr("host")
|
||||||
eventTypeJoin = ptrStr("join")
|
eventTypeJoin = ptrStr("join")
|
||||||
|
@ -28,6 +29,7 @@ var (
|
||||||
eventTypeBan,
|
eventTypeBan,
|
||||||
eventTypeBits,
|
eventTypeBits,
|
||||||
eventTypeClearChat,
|
eventTypeClearChat,
|
||||||
|
eventTypeFollow,
|
||||||
eventTypeGiftPaidUpgrade,
|
eventTypeGiftPaidUpgrade,
|
||||||
eventTypeHost,
|
eventTypeHost,
|
||||||
eventTypeJoin,
|
eventTypeJoin,
|
||||||
|
|
|
@ -42,6 +42,7 @@ const (
|
||||||
// eventSubStatusUserRemoved = "user_removed"
|
// eventSubStatusUserRemoved = "user_removed"
|
||||||
// eventSubStatusVerificationFailed = "webhook_callback_verification_failed"
|
// eventSubStatusVerificationFailed = "webhook_callback_verification_failed"
|
||||||
|
|
||||||
|
EventSubEventTypeChannelFollow = "channel.follow"
|
||||||
EventSubEventTypeChannelUpdate = "channel.update"
|
EventSubEventTypeChannelUpdate = "channel.update"
|
||||||
EventSubEventTypeStreamOffline = "stream.offline"
|
EventSubEventTypeStreamOffline = "stream.offline"
|
||||||
EventSubEventTypeStreamOnline = "stream.online"
|
EventSubEventTypeStreamOnline = "stream.online"
|
||||||
|
|
|
@ -183,10 +183,37 @@ func (t *twitchWatcher) registerEventSubCallbacks(channel string) (func(), error
|
||||||
return nil, errors.Wrap(err, "registering channel-update eventsub")
|
return nil, errors.Wrap(err, "registering channel-update eventsub")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsubFollow, err := twitchEventSubClient.RegisterEventSubHooks(
|
||||||
|
twitch.EventSubEventTypeChannelFollow,
|
||||||
|
twitch.EventSubCondition{BroadcasterUserID: userID},
|
||||||
|
func(m json.RawMessage) error {
|
||||||
|
var payload twitch.EventSubEventFollow
|
||||||
|
if err := json.Unmarshal(m, &payload); err != nil {
|
||||||
|
return errors.Wrap(err, "unmarshalling event")
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := plugins.FieldCollectionFromData(map[string]interface{}{
|
||||||
|
"channel": channel,
|
||||||
|
"followed_at": payload.FollowedAt,
|
||||||
|
"user_id": payload.UserID,
|
||||||
|
"user": payload.UserLogin,
|
||||||
|
})
|
||||||
|
|
||||||
|
log.WithFields(log.Fields(fields.Data())).Info("User followed")
|
||||||
|
go handleMessage(ircHdl.Client(), nil, eventTypeFollow, fields)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "registering channel-follow eventsub")
|
||||||
|
}
|
||||||
|
|
||||||
return func() {
|
return func() {
|
||||||
unsubCU()
|
unsubCU()
|
||||||
unsubSOff()
|
unsubSOff()
|
||||||
unsubSOn()
|
unsubSOn()
|
||||||
|
unsubFollow()
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,17 @@ Fields:
|
||||||
|
|
||||||
- `channel` - The channel the event occurred in
|
- `channel` - The channel the event occurred in
|
||||||
|
|
||||||
|
## `follow`
|
||||||
|
|
||||||
|
User followed the channel. This event is not de-duplicated and therefore might be used to spam! (Only available when EventSub support is available!)
|
||||||
|
|
||||||
|
Fields:
|
||||||
|
|
||||||
|
- `channel` - The channel the event occurred in
|
||||||
|
- `followed_at` - Time object of the follow date
|
||||||
|
- `user_id` - ID of the newly following user
|
||||||
|
- `user` - The login-name of the user who followed
|
||||||
|
|
||||||
## `giftpaidupgrade`
|
## `giftpaidupgrade`
|
||||||
|
|
||||||
User upgraded their gifted subscription into a paid one. This event does not contain any details about the tier of the paid subscription.
|
User upgraded their gifted subscription into a paid one. This event does not contain any details about the tier of the paid subscription.
|
||||||
|
|
Loading…
Reference in a new issue