Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

feat: add client.owner_ids #588

Merged
merged 3 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions naff/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def __init__(
intents: Union[int, Intents] = Intents.DEFAULT,
interaction_context: Type[InteractionContext] = InteractionContext,
logger: logging.Logger = logger,
owner_ids: Iterable["Snowflake_Type"] = (),
modal_context: Type[ModalContext] = ModalContext,
prefixed_context: Type[PrefixedContext] = PrefixedContext,
send_command_tracebacks: bool = True,
Expand Down Expand Up @@ -363,6 +364,7 @@ def __init__(
"""A dictionary of mounted ext"""
self.listeners: Dict[str, List] = {}
self.waits: Dict[str, List] = {}
self.owner_ids: set[Snowflake_Type] = set(owner_ids)

self.async_startup_tasks: list[Coroutine] = []
"""A list of coroutines to run during startup"""
Expand Down Expand Up @@ -435,6 +437,11 @@ def owner(self) -> Optional["User"]:
except TypeError:
return MISSING

@property
def owners(self) -> List["User"]:
"""Returns the bot's owners as declared via `client.owner_ids`."""
return [self.get_user(u_id) for u_id in self.owner_ids]

@property
def guilds(self) -> List["Guild"]:
"""Returns a list of all guilds the bot is in."""
Expand Down Expand Up @@ -783,6 +790,10 @@ async def login(self, token) -> None:
self.cache.place_user_data(me)
self._app = Application.from_dict(await self.http.get_current_bot_information(), self)
self._mention_reg = re.compile(rf"^(<@!?{self.user.id}*>\s)")

if self.app.owner:
self.owner_ids.add(self.app.owner.id)

self.dispatch(events.Login())

async def astart(self, token) -> None:
Expand Down
4 changes: 2 additions & 2 deletions naff/models/naff/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def check(ctx: Context) -> bool:

def is_owner() -> TYPE_CHECK_FUNCTION:
"""
Is the author the owner of the bot.
Checks if the author is the owner of the bot. This respects the `client.owner_ids` list.

Args:
coro: the function to check
Expand All @@ -72,7 +72,7 @@ def is_owner() -> TYPE_CHECK_FUNCTION:
async def check(ctx: Context) -> bool:
if ctx.bot.app.team:
return ctx.bot.app.team.is_in_team(ctx.author.id)
LordOfPolls marked this conversation as resolved.
Show resolved Hide resolved
return ctx.author.id == ctx.bot.owner.id
return ctx.author.id in ctx.bot.owner_ids

return check

Expand Down