From 84d02828156a49886c109ebcf311893bf96d8187 Mon Sep 17 00:00:00 2001 From: Jamie <31554168+flaree@users.noreply.github.com> Date: Sun, 21 Jun 2020 18:44:38 +0100 Subject: [PATCH] [Streams] Invalidate old bearer token when api key is updated. (#3990) --- redbot/cogs/streams/streams.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index e34d82bf5..62c2fa172 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -30,7 +30,7 @@ import aiohttp import contextlib from datetime import datetime from collections import defaultdict -from typing import Optional, List, Tuple, Union +from typing import Optional, List, Tuple, Union, Dict _ = Translator("Streams", __file__) log = logging.getLogger("red.core.cogs.Streams") @@ -100,6 +100,11 @@ class Streams(commands.Cog): self._ready_event.set() + @commands.Cog.listener() + async def on_red_api_tokens_update(self, service_name, api_tokens): + if service_name == "twitch": + await self.get_twitch_bearer_token(api_tokens) + async def cog_before_invoke(self, ctx: commands.Context): await self._ready_event.wait() @@ -116,8 +121,10 @@ class Streams(commands.Cog): await self.bot.set_shared_api_tokens("twitch", client_id=token) await self.config.tokens.clear() - async def get_twitch_bearer_token(self) -> None: - tokens = await self.bot.get_shared_api_tokens("twitch") + async def get_twitch_bearer_token(self, api_tokens: Optional[Dict] = None) -> None: + tokens = ( + await self.bot.get_shared_api_tokens("twitch") if api_tokens is None else api_tokens + ) if tokens.get("client_id"): notified_owner_missing_twitch_secret = ( await self.config.notified_owner_missing_twitch_secret()