From a13850067c9452f7a9146920a63d4ff2f8dcd3a5 Mon Sep 17 00:00:00 2001 From: Drapersniper <27962761+drapersniper@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:06:55 +0100 Subject: [PATCH] Update this to ensure `get_perms` is not called if the API is disabled --- redbot/cogs/audio/apis/global_db.py | 4 ++-- redbot/cogs/audio/core/commands/audioset.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/redbot/cogs/audio/apis/global_db.py b/redbot/cogs/audio/apis/global_db.py index 634768f01..6ed07dc78 100644 --- a/redbot/cogs/audio/apis/global_db.py +++ b/redbot/cogs/audio/apis/global_db.py @@ -34,7 +34,6 @@ class GlobalCacheWrapper: self.session = session self.api_key = None self._handshake_token = "" - self.can_write = False self._handshake_token = "" self.has_api_key = None self._token: Mapping[str, str] = {} @@ -164,7 +163,8 @@ class GlobalCacheWrapper: async def get_perms(self): global_api_user = copy(self.cog.global_api_user) await self._get_api_key() - if self.api_key is None: + is_enabled = await self.config.global_db_enabled() + if (not is_enabled) or self.api_key is None: return global_api_user with contextlib.suppress(aiohttp.ContentTypeError, asyncio.TimeoutError): async with aiohttp.ClientSession(json_serialize=json.dumps) as session: diff --git a/redbot/cogs/audio/core/commands/audioset.py b/redbot/cogs/audio/core/commands/audioset.py index 4811c9048..6d51d0e7f 100644 --- a/redbot/cogs/audio/core/commands/audioset.py +++ b/redbot/cogs/audio/core/commands/audioset.py @@ -1380,6 +1380,8 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass): """ state = await self.config.global_db_enabled() await self.config.global_db_enabled.set(not state) + if not state: # Ensure a call is made if the API is enabled to update user perms + self.global_api_user = await self.api_interface.global_cache_api.get_perms() await ctx.send( _("Global DB is {status}").format(status=_("enabled") if not state else _("disabled")) )