feat(aurora): converted mute to a hybrid command
Some checks failed
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 23s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 28s

This commit is contained in:
Seaswimmer 2024-03-07 16:13:47 -05:00
parent 246140da9b
commit e2d2b7bdc1
Signed by: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -401,32 +401,28 @@ class Aurora(commands.Cog):
case = await fetch_case(moderation_id, interaction.guild.id) case = await fetch_case(moderation_id, interaction.guild.id)
await send_evidenceformat(interaction, case) await send_evidenceformat(interaction, case)
@app_commands.command(name="mute") @commands.hybrid_command(name="mute")
@commands.mod_or_permissions(moderate_members=True)
@app_commands.describe(
target="Who are you muting?",
duration="How long are you muting this user for?",
reason="Why are you muting this user?",
silent="Should the user be messaged?",
)
async def mute( async def mute(
self, self,
interaction: discord.Interaction, ctx: commands.Context,
target: discord.Member, target: discord.Member,
duration: str, duration: str,
reason: str, reason: str,
silent: bool = None, silent: bool = None,
): ):
"""Mute a user. """Mute a user."""
if not await check_moddable(target, ctx, ["moderate_members"]):
Parameters
-----------
target: discord.Member
Who are you unbanning?
duration: str
How long are you muting this user for?
reason: str
Why are you unbanning this user?
silent: bool
Should the user be messaged?"""
if not await check_moddable(target, interaction, ["moderate_members"]):
return return
if target.is_timed_out() is True: if target.is_timed_out() is True:
await interaction.response.send_message( await ctx.send(
error(f"{target.mention} is already muted!"), error(f"{target.mention} is already muted!"),
allowed_mentions=discord.AllowedMentions(users=False), allowed_mentions=discord.AllowedMentions(users=False),
ephemeral=True, ephemeral=True,
@ -436,36 +432,36 @@ class Aurora(commands.Cog):
try: try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True) parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError: except ValueError:
await interaction.response.send_message( await ctx.send(
error("Please provide a valid duration!"), ephemeral=True error("Please provide a valid duration!"), ephemeral=True
) )
return return
if parsed_time.total_seconds() / 1000 > 2419200000: if parsed_time.total_seconds() / 1000 > 2419200000:
await interaction.response.send_message( await ctx.send(
error("Please provide a duration that is less than 28 days.") error("Please provide a duration that is less than 28 days.")
) )
return return
await target.timeout( await target.timeout(
parsed_time, reason=f"Muted by {interaction.user.id} for: {reason}" parsed_time, reason=f"Muted by {ctx.author.id} for: {reason}"
) )
await interaction.response.send_message( message = await ctx.send(
content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`" content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`"
) )
if silent is None: if silent is None:
silent = not await config.guild(interaction.guild).dm_users() silent = not await config.guild(ctx.guild).dm_users()
if silent is False: if silent is False:
try: try:
embed = await message_factory( embed = await message_factory(
await self.bot.get_embed_color(interaction.channel), await ctx.embed_color(),
guild=interaction.guild, guild=ctx.guild,
moderator=interaction.user, moderator=ctx.author,
reason=reason, reason=reason,
moderation_type="muted", moderation_type="muted",
response=await interaction.original_response(), response=message,
duration=parsed_time, duration=parsed_time,
) )
await target.send(embed=embed) await target.send(embed=embed)
@ -473,8 +469,8 @@ class Aurora(commands.Cog):
pass pass
moderation_id = await mysql_log( moderation_id = await mysql_log(
interaction.guild.id, ctx.guild.id,
interaction.user.id, ctx.author.id,
"MUTE", "MUTE",
"USER", "USER",
target.id, target.id,
@ -482,13 +478,13 @@ class Aurora(commands.Cog):
parsed_time, parsed_time,
reason, reason,
) )
await interaction.edit_original_response( await message.edit(
content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`" content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`"
) )
await log(interaction, moderation_id) await log(ctx, moderation_id)
case = await fetch_case(moderation_id, interaction.guild.id) case = await fetch_case(moderation_id, ctx.guild.id)
await send_evidenceformat(interaction, case) await send_evidenceformat(ctx, case)
@app_commands.command(name="unmute") @app_commands.command(name="unmute")
async def unmute( async def unmute(