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

Commit

Permalink
feat: add client.owner_ids (#588)
Browse files Browse the repository at this point in the history
* feat: add client.owner_ids

* feat: Respect app team members in `is_owner`

* fix: Im ashamed
  • Loading branch information
LordOfPolls committed Aug 9, 2022
1 parent b2e1857 commit db54f08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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
7 changes: 4 additions & 3 deletions naff/models/naff/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ 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
"""

async def check(ctx: Context) -> bool:
_owner_ids: set = ctx.bot.owner_ids.copy()
if ctx.bot.app.team:
return ctx.bot.app.team.is_in_team(ctx.author.id)
return ctx.author.id == ctx.bot.owner.id
[_owner_ids.add(m.id) for m in ctx.bot.app.team.members]
return ctx.author.id in _owner_ids

return check

Expand Down

0 comments on commit db54f08

Please sign in to comment.