feat: added skip_confirmation option
This commit is contained in:
parent
fb2b3037bd
commit
a03b9cac9a
1 changed files with 39 additions and 9 deletions
|
@ -17,7 +17,7 @@ class Shortmute(commands.Cog):
|
|||
|
||||
@app_commands.command()
|
||||
@app_commands.rename(target='member')
|
||||
async def shortmute(self, interaction: discord.Interaction, target: discord.Member, duration: int, reason: str, evidence_link: str = None, evidence_image: discord.Attachment = None):
|
||||
async def shortmute(self, interaction: discord.Interaction, target: discord.Member, duration: int, reason: str, evidence_link: str = None, evidence_image: discord.Attachment = None, skip_confirmation: bool = False):
|
||||
"""Shortmute someone for up to 30m.
|
||||
|
||||
Parameters
|
||||
|
@ -32,10 +32,15 @@ class Shortmute(commands.Cog):
|
|||
An image link to evidence for the shortmute, do not use with evidence_image
|
||||
evidence_image: discord.Attachment = None
|
||||
An image file used as evidence for the shortmute, do not use with evidence_link
|
||||
skip_confirmation: bool = False
|
||||
This allows you skip the confirmation prompt and immediately shortmute the user.
|
||||
"""
|
||||
disable_dateutil()
|
||||
timedelta = parse(f'{duration} minutes', as_timedelta=True)
|
||||
passed_info = {
|
||||
"target": target,
|
||||
"duration": duration,
|
||||
"timedelta": timedelta,
|
||||
"reason": reason,
|
||||
"interaction": interaction,
|
||||
"color": await self.bot.get_embed_color(None)
|
||||
|
@ -69,13 +74,38 @@ class Shortmute(commands.Cog):
|
|||
elif duration < 1:
|
||||
await interaction.response.send_message(content=f"Please shortmute the user for longer than {readable_duration}! The maximum duration is 30 minutes.", ephemeral=True)
|
||||
return
|
||||
embed = discord.Embed(title="Are you sure?", description=f"**Moderator:** {interaction.user.mention}\n**Target:** {target.mention}\n**Duration:** {readable_duration}\n**Reason:** `{reason}`", color=await self.bot.get_embed_color(None))
|
||||
if evidence:
|
||||
embed.set_image(url=evidence)
|
||||
passed_info.update({
|
||||
"evidence": evidence
|
||||
})
|
||||
await interaction.response.send_message(embed=embed, view=self.ShortmuteButtons(timeout=180, passed_info=passed_info), ephemeral=True)
|
||||
if skip_confirmation is False:
|
||||
embed = discord.Embed(title="Are you sure?", description=f"**Moderator:** {interaction.user.mention}\n**Target:** {target.mention}\n**Duration:** {readable_duration}\n**Reason:** `{reason}`", color=await self.bot.get_embed_color(None))
|
||||
if evidence:
|
||||
embed.set_image(url=evidence)
|
||||
passed_info.update({
|
||||
"evidence": evidence
|
||||
})
|
||||
await interaction.response.send_message(embed=embed, view=self.ShortmuteButtons(timeout=180, passed_info=passed_info), ephemeral=True)
|
||||
elif skip_confirmation is True:
|
||||
edit_embed = discord.Embed(title="Shortmute confirmed!", description=f"**Moderator:** {interaction.user.mention}\n**Target:** {target.mention}\n**Duration:** {readable_duration}\n**Reason:** `{reason}`", color=await self.bot.get_embed_color(None))
|
||||
if evidence:
|
||||
edit_embed.set_image(url=evidence)
|
||||
message = await interaction.response.send_message(embed=edit_embed, view=None)
|
||||
await target.timeout(timedelta, reason=f"User shortmuted for {readable_duration} by {interaction.user.name} ({interaction.user.id}) for: {reason}")
|
||||
await interaction.channel.send(content=f"{target.mention} was shortmuted for {readable_duration} by {interaction.user.mention} for: `{reason}`")
|
||||
if await self.config.guild(interaction.guild).dm() is True:
|
||||
dm_embed = discord.Embed(title=f"You've been shortmuted in {interaction.guild.name}!", description=f"**Moderator:** {interaction.user.mention}\n**Target:** {target.mention}\n**Duration:** {readable_duration}\n**Reason:** `{reason}`", color=await self.bot.get_embed_color(None))
|
||||
if evidence:
|
||||
dm_embed.set_image(url=evidence)
|
||||
try:
|
||||
await target.send(embed=dm_embed)
|
||||
except discord.HTTPException as error:
|
||||
await message.edit(content="Could not message the target, user most likely has Direct Messages disabled.")
|
||||
logging_channels_list = await self.config.guild(interaction.guild).logging_channels()
|
||||
if logging_channels_list:
|
||||
logging_embed = discord.Embed(title="User Shortmuted", description=f"**Moderator:** {interaction.user.mention} ({interaction.user.id})\n**Target:** {target.mention} ({target.id})\n**Duration:** {readable_duration}\n**Reason:** `{reason}`", color=await self.bot.get_embed_color(None))
|
||||
logging_embed.set_footer(text="/shortmute")
|
||||
if evidence:
|
||||
logging_embed.set_image(url=evidence)
|
||||
for channel_id in logging_channels_list:
|
||||
channel_obj = interaction.guild.get_channel(channel_id)
|
||||
await channel_obj.send(embed=logging_embed)
|
||||
|
||||
class ShortmuteButtons(ui.View):
|
||||
def __init__(self, timeout, passed_info: dict):
|
||||
|
@ -93,7 +123,7 @@ class Shortmute(commands.Cog):
|
|||
reason = self.passed_info['reason']
|
||||
old_interaction = self.passed_info['interaction']
|
||||
color = self.passed_info['color']
|
||||
timedelta = parse(f'{duration} minutes', as_timedelta=True)
|
||||
timedelta = self.passed_info['timedelta']
|
||||
edit_embed = discord.Embed(title="Shortmute confirmed!", description=f"**Moderator:** {old_interaction.user.mention}\n**Target:** {target.mention}\n**Duration:** {readable_duration}\n**Reason:** `{reason}`", color=color)
|
||||
if self.passed_info.get('evidence'):
|
||||
evidence = self.passed_info['evidence']
|
||||
|
|
Loading…
Reference in a new issue