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>
This commit is contained in:
Kowlin 2020-04-24 18:03:58 +02:00 committed by GitHub
parent e595f1859a
commit bf6390d72e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -170,6 +170,8 @@ class RedBase(
self._main_dir = bot_dir self._main_dir = bot_dir
self._cog_mgr = CogManager() self._cog_mgr = CogManager()
self._use_team_features = cli_flags.use_team_features 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) super().__init__(*args, help_command=None, **kwargs)
# Do not manually use the help formatter attribute here, see `send_help_for`, # 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. # 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: if user.id in self._co_owners:
return True return True
ret = False
if self.owner_id: if self.owner_id:
return self.owner_id == user.id return self.owner_id == user.id
elif self.owner_ids: elif self.owner_ids:
return user.id in self.owner_ids return user.id in self.owner_ids
else: elif not self._app_owners_fetched:
app = await self.application_info() app = await self.application_info()
if app.team: if app.team:
if self._use_team_features: if self._use_team_features:
self.owner_ids = ids = {m.id for m in app.team.members} self.owner_ids = ids = {m.id for m in app.team.members}
return user.id in ids ret = user.id in ids
else: else:
self.owner_id = owner_id = app.owner.id 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: async def is_admin(self, member: discord.Member) -> bool:
"""Checks if a member is an admin of their guild.""" """Checks if a member is an admin of their guild."""

View File

@ -61,6 +61,7 @@ def init_events(bot, cli_flags):
else: else:
if bot.owner_id is None: if bot.owner_id is None:
bot.owner_id = app_info.owner.id bot.owner_id = app_info.owner.id
bot._app_owners_fetched = True
try: try:
invite_url = discord.utils.oauth_url(app_info.id) invite_url = discord.utils.oauth_url(app_info.id)