Extract populate_owners into a new coroutine.
This commit is contained in:
@@ -344,14 +344,22 @@ class BotBase(GroupMixin):
|
|||||||
elif self.owner_ids:
|
elif self.owner_ids:
|
||||||
return user.id in self.owner_ids
|
return user.id in self.owner_ids
|
||||||
else:
|
else:
|
||||||
|
# Populate the used fields, then retry the check. This is only done at-most once in the bot lifetime.
|
||||||
|
await self.populate_owners()
|
||||||
|
return await self.is_owner(user)
|
||||||
|
|
||||||
app = await self.application_info() # type: ignore
|
async def populate_owners(self):
|
||||||
if app.team:
|
"""|coro|
|
||||||
self.owner_ids = ids = {m.id for m in app.team.members}
|
|
||||||
return user.id in ids
|
Populate the :meth:`.Bot.owner_id` and :meth:`.Bot.owner_ids` through the use of :meth:`~.Bot.application_info`.
|
||||||
else:
|
|
||||||
self.owner_id = owner_id = app.owner.id
|
.. versionadded:: 2.0
|
||||||
return user.id == owner_id
|
"""
|
||||||
|
app = await self.application_info() # type: ignore
|
||||||
|
if app.team:
|
||||||
|
self.owner_ids = {m.id for m in app.team.members}
|
||||||
|
else:
|
||||||
|
self.owner_id = app.owner.id
|
||||||
|
|
||||||
def before_invoke(self, coro: CFT) -> CFT:
|
def before_invoke(self, coro: CFT) -> CFT:
|
||||||
"""A decorator that registers a coroutine as a pre-invoke hook.
|
"""A decorator that registers a coroutine as a pre-invoke hook.
|
||||||
|
Reference in New Issue
Block a user