Skip to content

Commit

Permalink
refactor(bot): use _fill_owners in Bot.is_owner instead of reimpl…
Browse files Browse the repository at this point in the history
…ementing logic
  • Loading branch information
shiftinv committed Sep 22, 2023
1 parent 5a3d5a0 commit ca5911c
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions disnake/ext/commands/common_bot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ async def _fill_owners(self) -> None:
if self.owner_id or self.owner_ids:
return

await self.wait_until_first_connect() # type: ignore

app = await self.application_info() # type: ignore
app: disnake.AppInfo = await self.application_info() # type: ignore
if app.team:
self.owners = set(app.team.members)
self.owner_ids = {m.id for m in app.team.members}
Expand Down Expand Up @@ -111,11 +109,13 @@ async def close(self) -> None:

@disnake.utils.copy_doc(disnake.Client.login)
async def login(self, token: str) -> None:
self.loop.create_task(self._fill_owners()) # type: ignore
await super().login(token=token) # type: ignore

if self.reload:
self.loop.create_task(self._watchdog()) # type: ignore
await super().login(token=token) # type: ignore

# prefetch
self.loop.create_task(self._fill_owners()) # type: ignore

async def is_owner(self, user: Union[disnake.User, disnake.Member]) -> bool:
"""|coro|
Expand All @@ -140,20 +140,13 @@ async def is_owner(self, user: Union[disnake.User, disnake.Member]) -> bool:
:class:`bool`
Whether the user is the owner.
"""
if not self.owner_id and not self.owner_ids:
await self._fill_owners()

if self.owner_id:
return user.id == self.owner_id
elif self.owner_ids:
return user.id in self.owner_ids
else:
app = await self.application_info() # type: ignore
if app.team:
self.owners = set(app.team.members)
self.owner_ids = ids = {m.id for m in app.team.members}
return user.id in ids
else:
self.owner = app.owner
self.owner_id = owner_id = app.owner.id
return user.id == owner_id
return user.id in self.owner_ids

def add_cog(self, cog: Cog, *, override: bool = False) -> None:
"""Adds a "cog" to the bot.
Expand Down

0 comments on commit ca5911c

Please sign in to comment.