From fbc76761b498bd1fdf764b98842e8f3947cfc3a9 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 29 Sep 2023 14:54:24 +0200 Subject: [PATCH] [core] Fix: Replace deprecated follow API - add `moderator:read:followers` scope to bot-defaults - document requirement of bot to be mod to read followers - adjust `GetFollowDate` method to use new channel followers endpoint Signed-off-by: Knut Ahlers --- docs/content/configuration/templating.md | 10 +++++----- internal/template/twitch/follow.go | 8 ++++---- pkg/twitch/users.go | 4 ++-- scopes.go | 1 + 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/content/configuration/templating.md b/docs/content/configuration/templating.md index aac588b..4ac7483 100644 --- a/docs/content/configuration/templating.md +++ b/docs/content/configuration/templating.md @@ -141,7 +141,7 @@ Example: ### `doesFollow` -Returns whether `from` follows `to` +Returns whether `from` follows `to` (the bot must be moderator of `to` to read this) Syntax: `doesFollow ` @@ -154,7 +154,7 @@ Example: ### `doesFollowLongerThan` -Returns whether `from` follows `to` for more than `duration` +Returns whether `from` follows `to` for more than `duration` (the bot must be moderator of `to` to read this) Syntax: `doesFollowLongerThan ` @@ -180,7 +180,7 @@ Example: ### `followAge` -Looks up when `from` followed `to` and returns the duration between then and now +Looks up when `from` followed `to` and returns the duration between then and now (the bot must be moderator of `to` to read this) Syntax: `followAge ` @@ -193,7 +193,7 @@ Example: ### `followDate` -Looks up when `from` followed `to` +Looks up when `from` followed `to` (the bot must be moderator of `to` to read this) Syntax: `followDate ` @@ -389,7 +389,7 @@ Example: ``` # Your int this hour: {{ printf "%.0f" (mulf (seededRandom (list "int" .username (now | date "2006-01-02 15") | join ":")) 100) }}% -< Your int this hour: 46% +< Your int this hour: 11% ``` ### `streamUptime` diff --git a/internal/template/twitch/follow.go b/internal/template/twitch/follow.go index cbfd01c..e33156a 100644 --- a/internal/template/twitch/follow.go +++ b/internal/template/twitch/follow.go @@ -50,7 +50,7 @@ func tplTwitchDoesFollowLongerThan(args plugins.RegistrationArguments) { return false, errors.Wrap(err, "getting follow date") } }), plugins.TemplateFuncDocumentation{ - Description: "Returns whether `from` follows `to` for more than `duration`", + Description: "Returns whether `from` follows `to` for more than `duration` (the bot must be moderator of `to` to read this)", Syntax: "doesFollowLongerThan ", Example: &plugins.TemplateFuncDocumentationExample{ Template: `{{ doesFollowLongerThan "tezrian" "luziferus" "168h" }}`, @@ -73,7 +73,7 @@ func tplTwitchDoesFollow(args plugins.RegistrationArguments) { return false, errors.Wrap(err, "getting follow date") } }), plugins.TemplateFuncDocumentation{ - Description: "Returns whether `from` follows `to`", + Description: "Returns whether `from` follows `to` (the bot must be moderator of `to` to read this)", Syntax: "doesFollow ", Example: &plugins.TemplateFuncDocumentationExample{ Template: `{{ doesFollow "tezrian" "luziferus" }}`, @@ -87,7 +87,7 @@ func tplTwitchFollowAge(args plugins.RegistrationArguments) { since, err := args.GetTwitchClient().GetFollowDate(from, to) return time.Since(since), errors.Wrap(err, "getting follow date") }), plugins.TemplateFuncDocumentation{ - Description: "Looks up when `from` followed `to` and returns the duration between then and now", + Description: "Looks up when `from` followed `to` and returns the duration between then and now (the bot must be moderator of `to` to read this)", Syntax: "followAge ", Example: &plugins.TemplateFuncDocumentationExample{ Template: `{{ followAge "tezrian" "luziferus" }}`, @@ -100,7 +100,7 @@ func tplTwitchFollowDate(args plugins.RegistrationArguments) { args.RegisterTemplateFunction("followDate", plugins.GenericTemplateFunctionGetter(func(from, to string) (time.Time, error) { return args.GetTwitchClient().GetFollowDate(from, to) }), plugins.TemplateFuncDocumentation{ - Description: "Looks up when `from` followed `to`", + Description: "Looks up when `from` followed `to` (the bot must be moderator of `to` to read this)", Syntax: "followDate ", Example: &plugins.TemplateFuncDocumentationExample{ Template: `{{ followDate "tezrian" "luziferus" }}`, diff --git a/pkg/twitch/users.go b/pkg/twitch/users.go index ed5786d..bd46a2d 100644 --- a/pkg/twitch/users.go +++ b/pkg/twitch/users.go @@ -104,7 +104,7 @@ func (c *Client) GetFollowDate(from, to string) (time.Time, error) { Method: http.MethodGet, OKStatus: http.StatusOK, Out: &payload, - URL: fmt.Sprintf("https://api.twitch.tv/helix/users/follows?to_id=%s&from_id=%s", toID, fromID), + URL: fmt.Sprintf("https://api.twitch.tv/helix/channels/followers?broadcaster_id=%s&user_id=%s", toID, fromID), }); err != nil { return time.Time{}, errors.Wrap(err, "request follow info") } @@ -228,7 +228,7 @@ func (c *Client) GetUserInformation(user string) (*User, error) { return nil, errors.Errorf("unexpected number of records returned: %d", l) } - // Follow date will not change that often, cache for a long time + // User info will not change that often, cache for a long time c.apiCache.Set(cacheKey, timeDay, payload.Data[0]) out = payload.Data[0] diff --git a/scopes.go b/scopes.go index bff877c..5978161 100644 --- a/scopes.go +++ b/scopes.go @@ -26,6 +26,7 @@ var ( twitch.ScopeModeratorManageChatSettings, twitch.ScopeModeratorManageShieldMode, twitch.ScopeModeratorManageShoutouts, + twitch.ScopeModeratorReadFollowers, // Chat Scopes twitch.ScopeChatEdit,