Skip to content
Merged
Changes from all commits
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
20 changes: 16 additions & 4 deletions utils/command_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ def check_interaction_user_in_main_guild[T: TeXBotBaseCog, **P](
Instead, an error message will be sent to the user.
""" # noqa: D401

async def _check(ctx: TeXBotApplicationContext) -> bool:
# NOTE: The check function shares this decorator's name, so that `is_interaction_user_in_main_guild_failure()` can identify it within a `CheckAnyFailure`
async def check_interaction_user_in_main_guild(ctx: TeXBotApplicationContext) -> bool:
try:
await ctx.bot.get_main_guild_member(ctx.user)
except DiscordMemberNotInMainGuildError:
return False
return True

return commands.check_any(commands.check(_check))(func) # type: ignore[arg-type]
return commands.check_any(
commands.check(
check_interaction_user_in_main_guild # type: ignore[arg-type]
)
)(func)

@staticmethod
def check_interaction_user_has_committee_role[T: TeXBotBaseCog, **P](
Expand All @@ -48,10 +53,17 @@ def check_interaction_user_has_committee_role[T: TeXBotBaseCog, **P](
Instead, an error message will be sent to the user.
"""

async def _check(ctx: TeXBotApplicationContext) -> bool:
# NOTE: The check function shares this decorator's name, so that `is_interaction_user_has_committee_role_failure()` can identify it within a `CheckAnyFailure`
async def check_interaction_user_has_committee_role(
ctx: TeXBotApplicationContext,
) -> bool:
return await ctx.bot.check_user_has_committee_role(ctx.user)

return commands.check_any(commands.check(_check))(func) # type: ignore[arg-type]
return commands.check_any(
commands.check(
check_interaction_user_has_committee_role # type: ignore[arg-type]
)
)(func)

@classmethod
def is_interaction_user_in_main_guild_failure(cls, check: CheckFailure) -> bool:
Expand Down