Skip to content

Commit

Permalink
Change check and add error handler for query hours
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCatster committed Mar 5, 2022
1 parent 85f78b2 commit bb3d47b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/extensions/timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
query_hours,
hours_to_export,
)
from hikari import Embed
from hikari import Embed, Permissions

timesheet = lightbulb.Plugin("Timesheet")

Expand Down Expand Up @@ -43,7 +43,7 @@ async def query(ctx: lightbulb.Context) -> None:


@hours.child
@lightbulb.add_checks(lightbulb.owner_only)
@lightbulb.add_checks(lightbulb.has_role_permissions(Permissions.ADMINISTRATOR))
@lightbulb.command(
name="query_all",
description="Check all users' hours. Usable only by owner.",
Expand Down Expand Up @@ -162,6 +162,14 @@ async def add(ctx: lightbulb.Context) -> None:
await query_hours(author_id=ctx.author.id, ctx=ctx)


@bot.app.listen(lightbulb.CommandErrorEvent)
async def on_error(event: lightbulb.CommandErrorEvent) -> None:
exception = event.exception.__cause__ or event.exception

if isinstance(exception, lightbulb.MissingRequiredPermission):
await event.context.respond("You are not an administrator.")


def load(bot) -> None:
bot.add_plugin(timesheet)

Expand Down

0 comments on commit bb3d47b

Please sign in to comment.