From bf6390d72e9b9f4cd630c3a66b7d6f68ebc5f619 Mon Sep 17 00:00:00 2001 From: Kowlin Date: Fri, 24 Apr 2020 18:03:58 +0200 Subject: [PATCH] Fix Owner ID failsafe (#3782) * Fix Owner ID failsafe * Update redbot/core/bot.py Co-Authored-By: jack1142 <6032823+jack1142@users.noreply.github.com> * Let's go with a different approach (first commit) * Let's go with a different approach (last commit) Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/core/bot.py | 13 +++++++++---- redbot/core/events.py | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 8126eacda..3e7b002dc 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -170,6 +170,8 @@ class RedBase( self._main_dir = bot_dir self._cog_mgr = CogManager() self._use_team_features = cli_flags.use_team_features + # to prevent multiple calls to app info in `is_owner()` + self._app_owners_fetched = False super().__init__(*args, help_command=None, **kwargs) # Do not manually use the help formatter attribute here, see `send_help_for`, # for a documented API. The internals of this object are still subject to change. @@ -704,21 +706,24 @@ class RedBase( if user.id in self._co_owners: return True + ret = False + if self.owner_id: return self.owner_id == user.id elif self.owner_ids: return user.id in self.owner_ids - else: + elif not self._app_owners_fetched: app = await self.application_info() if app.team: if self._use_team_features: self.owner_ids = ids = {m.id for m in app.team.members} - return user.id in ids + ret = user.id in ids else: self.owner_id = owner_id = app.owner.id - return user.id == owner_id + ret = user.id == owner_id + self._app_owners_fetched = True - return False + return ret async def is_admin(self, member: discord.Member) -> bool: """Checks if a member is an admin of their guild.""" diff --git a/redbot/core/events.py b/redbot/core/events.py index 0fc432a75..c961bf935 100644 --- a/redbot/core/events.py +++ b/redbot/core/events.py @@ -61,6 +61,7 @@ def init_events(bot, cli_flags): else: if bot.owner_id is None: bot.owner_id = app_info.owner.id + bot._app_owners_fetched = True try: invite_url = discord.utils.oauth_url(app_info.id)