Skip to content

Commit

Permalink
Document hook errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial committed Jan 26, 2024
1 parent 8414601 commit 808cf03
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions arc/utils/hooks/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def guild_only(ctx: Context[t.Any]) -> HookResult:
```py
@arc.with_hook(arc.guild_only)
```
Raises
------
GuildOnlyError
If the command is invoked outside of a guild.
"""
if ctx.guild_id is None:
raise GuildOnlyError("This command can only be used in a guild.")
Expand All @@ -39,6 +44,11 @@ def dm_only(ctx: Context[t.Any]) -> HookResult:
```py
@arc.with_hook(arc.dm_only)
```
Raises
------
DMOnlyError
If the command is invoked outside of a DM.
"""
if ctx.guild_id is not None:
raise DMOnlyError("This command can only be used in a DM.")
Expand All @@ -53,6 +63,11 @@ def owner_only(ctx: Context[t.Any]) -> HookResult:
```py
@arc.with_hook(arc.owner_only)
```
Raises
------
NotOwnerError
If the command is invoked by a non-owner.
"""
if ctx.author.id not in ctx.client.owner_ids:
raise NotOwnerError("This command can only be used by the application owners.")
Expand Down Expand Up @@ -83,6 +98,13 @@ def has_permissions(perms: hikari.Permissions) -> t.Callable[[Context[t.Any]], H
perms : hikari.Permissions
The permissions to check for.
Raises
------
GuildOnlyError
If the command is invoked outside of a guild.
InvokerMissingPermissionsError
If the invoker is missing some of the specified permissions.
Examples
--------
```py
Expand Down Expand Up @@ -120,6 +142,13 @@ def bot_has_permissions(perms: hikari.Permissions) -> t.Callable[[Context[t.Any]
perms : hikari.Permissions
The permissions to check for.
Raises
------
GuildOnlyError
If the command is invoked outside of a guild.
BotMissingPermissionsError
If the bot is missing some of the specified permissions.
Examples
--------
```py
Expand Down
30 changes: 30 additions & 0 deletions arc/utils/hooks/limiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def global_limiter(period: float, limit: int) -> LimiterHook[t.Any]:
limit : int
The amount of requests allowed in a bucket.
Raises
------
RateLimiterExhaustedError
If the limiter is exhausted.
Examples
--------
```py
Expand All @@ -98,6 +103,11 @@ def guild_limiter(period: float, limit: int) -> LimiterHook[t.Any]:
limit : int
The amount of requests allowed in a bucket.
Raises
------
RateLimiterExhaustedError
If the limiter is exhausted.
Examples
--------
```py
Expand All @@ -119,6 +129,11 @@ def channel_limiter(period: float, limit: int) -> LimiterHook[t.Any]:
limit : int
The amount of requests allowed in a bucket.
Raises
------
RateLimiterExhaustedError
If the limiter is exhausted.
Examples
--------
```py
Expand All @@ -140,6 +155,11 @@ def user_limiter(period: float, limit: int) -> LimiterHook[t.Any]:
limit : int
The amount of requests allowed in a bucket.
Raises
------
RateLimiterExhaustedError
If the limiter is exhausted.
Examples
--------
```py
Expand All @@ -162,6 +182,11 @@ def member_limiter(period: float, limit: int) -> LimiterHook[t.Any]:
limit : int
The amount of requests allowed in a bucket.
Raises
------
RateLimiterExhaustedError
If the limiter is exhausted.
Examples
--------
```py
Expand All @@ -185,6 +210,11 @@ def custom_limiter(period: float, limit: int, get_key_with: t.Callable[[Context[
For instance, to create a ratelimiter that is shared across all contexts in a guild,
you would use `lambda ctx: str(ctx.guild_id)`.
Raises
------
RateLimiterExhaustedError
If the limiter is exhausted.
Examples
--------
```py
Expand Down

0 comments on commit 808cf03

Please sign in to comment.