Skip to content

Commit e4b1cfe

Browse files
implement get strikes command
1 parent 6eb8333 commit e4b1cfe

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

cogs/strike.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,48 @@ async def strike(self, ctx: "TeXBotApplicationContext", str_strike_member_id: st
865865

866866
await self._command_perform_strike(ctx, strike_member)
867867

868+
@discord.slash_command( # type: ignore[misc, no-untyped-call]
869+
name="get-strikes",
870+
description="Get the number of strikes a user has.",
871+
)
872+
@discord.option( # type: ignore[misc, no-untyped-call]
873+
name="user",
874+
description="The user to give a strike to.",
875+
input_type=str,
876+
autocomplete=discord.utils.basic_autocomplete(autocomplete_get_members), # type: ignore[arg-type]
877+
required=True,
878+
parameter_name="str_strike_member_id",
879+
)
880+
@CommandChecks.check_interaction_user_has_committee_role
881+
@CommandChecks.check_interaction_user_in_main_guild
882+
async def get_strikes(
883+
self, ctx: "TeXBotApplicationContext", str_strike_member_id: str
884+
) -> None: # type: ignore[misc]
885+
"""
886+
Define method and callback response of of the "get-strikes" command.
887+
888+
Returns the number of strikes a user has.
889+
"""
890+
member_id_not_integer_error: ValueError
891+
try:
892+
strike_member: discord.Member = await self.bot.get_member_from_str_id(
893+
str_strike_member_id,
894+
)
895+
except ValueError as member_id_not_integer_error:
896+
await self.command_send_error(ctx, message=member_id_not_integer_error.args[0])
897+
return
898+
899+
member_strikes = [
900+
strike
901+
async for strike in await DiscordMemberStrikes.objects.afilter(
902+
discord_id=str(strike_member.id),
903+
)
904+
]
905+
906+
await ctx.respond(
907+
f"User {strike_member.mention} has the following strikes: {member_strikes}"
908+
)
909+
868910

869911
class StrikeContextCommandsCog(BaseStrikeCog):
870912
"""Cog class that defines the context menu strike command and its call-back method."""

0 commit comments

Comments
 (0)