From 5a3d5a0ba25862f4d317e7388fe2dcba66c0dabf Mon Sep 17 00:00:00 2001 From: shiftinv Date: Fri, 22 Sep 2023 19:21:41 +0200 Subject: [PATCH 1/3] docs: smol fixes --- disnake/ext/commands/bot.py | 8 ++++---- disnake/ext/commands/common_bot_base.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/disnake/ext/commands/bot.py b/disnake/ext/commands/bot.py index 5e135d829c..5c3ba59eac 100644 --- a/disnake/ext/commands/bot.py +++ b/disnake/ext/commands/bot.py @@ -175,14 +175,14 @@ class Bot(BotBase, InteractionBotBase, disnake.Client): This can be provided as a parameter at creation. owner_id: Optional[:class:`int`] - The user ID that owns the bot. If this is not set and is then queried via + The ID of the user that owns the bot. If this is not set and is then queried via :meth:`.is_owner` then it is fetched automatically using :meth:`~.Bot.application_info`. This can be provided as a parameter at creation. owner_ids: Optional[Collection[:class:`int`]] - The user IDs that owns the bot. This is similar to :attr:`owner_id`. + The IDs of the users that own the bot. This is similar to :attr:`owner_id`. If this is not set and the application is team based, then it is fetched automatically using :meth:`~.Bot.application_info`. For performance reasons it is recommended to use a :class:`set` @@ -394,14 +394,14 @@ class InteractionBot(InteractionBotBase, disnake.Client): Attributes ---------- owner_id: Optional[:class:`int`] - The user ID that owns the bot. If this is not set and is then queried via + The ID of the user that owns the bot. If this is not set and is then queried via :meth:`.is_owner` then it is fetched automatically using :meth:`~.Bot.application_info`. This can be provided as a parameter at creation. owner_ids: Optional[Collection[:class:`int`]] - The user IDs that owns the bot. This is similar to :attr:`owner_id`. + The IDs of the users that own the bot. This is similar to :attr:`owner_id`. If this is not set and the application is team based, then it is fetched automatically using :meth:`~.Bot.application_info`. For performance reasons it is recommended to use a :class:`set` diff --git a/disnake/ext/commands/common_bot_base.py b/disnake/ext/commands/common_bot_base.py index dc4e81c97c..05728bedc4 100644 --- a/disnake/ext/commands/common_bot_base.py +++ b/disnake/ext/commands/common_bot_base.py @@ -123,7 +123,7 @@ async def is_owner(self, user: Union[disnake.User, disnake.Member]) -> bool: Checks if a :class:`~disnake.User` or :class:`~disnake.Member` is the owner of this bot. - If an :attr:`owner_id` is not set, it is fetched automatically + If :attr:`owner_id` and :attr:`owner_ids` are not set, they are fetched automatically through the use of :meth:`~.Bot.application_info`. .. versionchanged:: 1.3 From ca5911cb1c032c570243998acc92a02b87e201ea Mon Sep 17 00:00:00 2001 From: shiftinv Date: Fri, 22 Sep 2023 19:21:15 +0200 Subject: [PATCH 2/3] refactor(bot): use `_fill_owners` in `Bot.is_owner` instead of reimplementing logic --- disnake/ext/commands/common_bot_base.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/disnake/ext/commands/common_bot_base.py b/disnake/ext/commands/common_bot_base.py index 05728bedc4..0e7076190a 100644 --- a/disnake/ext/commands/common_bot_base.py +++ b/disnake/ext/commands/common_bot_base.py @@ -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} @@ -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| @@ -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. From 36873125a196cea69aad8bbb84a81d64b206a26a Mon Sep 17 00:00:00 2001 From: shiftinv Date: Fri, 22 Sep 2023 19:50:48 +0200 Subject: [PATCH 3/3] one `# type: ignore` down, 5631 to go --- disnake/ext/commands/common_bot_base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/disnake/ext/commands/common_bot_base.py b/disnake/ext/commands/common_bot_base.py index 0e7076190a..841c3df837 100644 --- a/disnake/ext/commands/common_bot_base.py +++ b/disnake/ext/commands/common_bot_base.py @@ -111,11 +111,12 @@ async def close(self) -> None: async def login(self, token: str) -> None: await super().login(token=token) # type: ignore + loop: asyncio.AbstractEventLoop = self.loop # type: ignore if self.reload: - self.loop.create_task(self._watchdog()) # type: ignore + loop.create_task(self._watchdog()) # prefetch - self.loop.create_task(self._fill_owners()) # type: ignore + loop.create_task(self._fill_owners()) async def is_owner(self, user: Union[disnake.User, disnake.Member]) -> bool: """|coro|