mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 08:40:01 +00:00
[eventsub] Switch to v2 follows topic
as Twitch changed the policy which applications can use the v1 endpoint > Update (2023-02-23): The deprecated “Get Users Follows” API > endpoint and channel.follow (v1) EventSub subscription type now > have limited access to minimize usage in new development leading up > to the August 3 decommission date. The API endpoint is accessible > to client IDs that have made requests on or before February 17, > 2023. The v1 EventSub subscription type is accessible to client IDs > that had an active subscription on February 17, 2023. > (https://discuss.dev.twitch.tv/t/follows-endpoints-and-eventsub-subscription-type-are-now-available-in-open-beta/43322) Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
f066b3fd2a
commit
7126f6d7b7
2 changed files with 16 additions and 13 deletions
|
@ -297,7 +297,7 @@ func (e *EventSubClient) HandleEventsubPush(w http.ResponseWriter, r *http.Reque
|
|||
e.subscriptionsLock.RLock()
|
||||
defer e.subscriptionsLock.RUnlock()
|
||||
|
||||
cacheKey := strings.Join([]string{message.Subscription.Type, condHash}, "::")
|
||||
cacheKey := strings.Join([]string{message.Subscription.Type, message.Subscription.Version, condHash}, "::")
|
||||
|
||||
reg, ok := e.subscriptions[cacheKey]
|
||||
if !ok {
|
||||
|
@ -336,8 +336,9 @@ func (e *EventSubClient) PreFetchSubscriptions(ctx context.Context) error {
|
|||
// so we should be able to deregister it without causing any
|
||||
// trouble
|
||||
logger := log.WithFields(log.Fields{
|
||||
"id": sub.ID,
|
||||
"topic": sub.Type,
|
||||
"id": sub.ID,
|
||||
"topic": sub.Type,
|
||||
"version": sub.Version,
|
||||
})
|
||||
logger.Debug("Removing deprecated EventSub subscription")
|
||||
if err = e.twitchClient.deleteEventSubSubscription(ctx, sub.ID); err != nil {
|
||||
|
@ -359,9 +360,10 @@ func (e *EventSubClient) PreFetchSubscriptions(ctx context.Context) error {
|
|||
log.WithFields(log.Fields{
|
||||
"condition": sub.Condition,
|
||||
"type": sub.Type,
|
||||
"version": sub.Version,
|
||||
}).Debug("found existing eventsub subscription")
|
||||
|
||||
cacheKey := strings.Join([]string{sub.Type, condHash}, "::")
|
||||
cacheKey := strings.Join([]string{sub.Type, sub.Version, condHash}, "::")
|
||||
e.subscriptions[cacheKey] = ®isteredSubscription{
|
||||
Type: sub.Type,
|
||||
Callbacks: map[string]func(json.RawMessage) error{},
|
||||
|
@ -383,8 +385,12 @@ func (e *EventSubClient) RegisterEventSubHooks(event, version string, condition
|
|||
}
|
||||
|
||||
var (
|
||||
cacheKey = strings.Join([]string{event, condHash}, "::")
|
||||
logger = log.WithField("event", event)
|
||||
cacheKey = strings.Join([]string{event, version, condHash}, "::")
|
||||
logger = log.WithFields(log.Fields{
|
||||
"condition": condition,
|
||||
"type": event,
|
||||
"version": version,
|
||||
})
|
||||
)
|
||||
|
||||
e.subscriptionsLock.RLock()
|
||||
|
@ -404,10 +410,7 @@ func (e *EventSubClient) RegisterEventSubHooks(event, version string, condition
|
|||
return func() { e.unregisterCallback(cacheKey, cbKey) }, nil
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"condition": condition,
|
||||
"type": event,
|
||||
}).Debug("registering new eventsub subscription")
|
||||
logger.Debug("registering new eventsub subscription")
|
||||
|
||||
// Register subscriptions
|
||||
ctx, cancel := context.WithTimeout(context.Background(), twitchRequestTimeout)
|
||||
|
|
|
@ -125,9 +125,9 @@ func (t *twitchWatcher) getTopicRegistrations(userID string) []topicRegistration
|
|||
},
|
||||
{
|
||||
Topic: twitch.EventSubEventTypeChannelFollow,
|
||||
Version: twitch.EventSubTopicVersion1, // DEPRECATED, to be removed August 3, 2023
|
||||
Condition: twitch.EventSubCondition{BroadcasterUserID: userID},
|
||||
RequiredScopes: nil, // Switch to []string{twitch.ScopeModeratorReadFollowers} after August 3, 2023
|
||||
Version: twitch.EventSubTopicVersion2,
|
||||
Condition: twitch.EventSubCondition{BroadcasterUserID: userID, ModeratorUserID: userID},
|
||||
RequiredScopes: []string{twitch.ScopeModeratorReadFollowers},
|
||||
Hook: t.handleEventSubChannelFollow,
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue