mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-30 00:21:16 +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")
|
||||
eventTypeBits = ptrStr("bits")
|
||||
eventTypeClearChat = ptrStr("clearchat")
|
||||
eventTypeFollow = ptrStr("follow")
|
||||
eventTypeGiftPaidUpgrade = ptrStr("giftpaidupgrade")
|
||||
eventTypeHost = ptrStr("host")
|
||||
eventTypeJoin = ptrStr("join")
|
||||
|
@ -28,6 +29,7 @@ var (
|
|||
eventTypeBan,
|
||||
eventTypeBits,
|
||||
eventTypeClearChat,
|
||||
eventTypeFollow,
|
||||
eventTypeGiftPaidUpgrade,
|
||||
eventTypeHost,
|
||||
eventTypeJoin,
|
||||
|
|
|
@ -42,6 +42,7 @@ const (
|
|||
// eventSubStatusUserRemoved = "user_removed"
|
||||
// eventSubStatusVerificationFailed = "webhook_callback_verification_failed"
|
||||
|
||||
EventSubEventTypeChannelFollow = "channel.follow"
|
||||
EventSubEventTypeChannelUpdate = "channel.update"
|
||||
EventSubEventTypeStreamOffline = "stream.offline"
|
||||
EventSubEventTypeStreamOnline = "stream.online"
|
||||
|
|
|
@ -183,10 +183,37 @@ func (t *twitchWatcher) registerEventSubCallbacks(channel string) (func(), error
|
|||
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() {
|
||||
unsubCU()
|
||||
unsubSOff()
|
||||
unsubSOn()
|
||||
unsubFollow()
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,17 @@ Fields:
|
|||
|
||||
- `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`
|
||||
|
||||
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