feat(moderation): added timeout command

This commit is contained in:
SeaswimmerTheFsh 2023-10-04 12:44:21 -04:00
parent 854a1f14e5
commit 57f49d8e42
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -60,8 +60,9 @@ class Moderation(commands.Cog):
@commands.Cog.listener('on_audit_log_entry_create')
async def autologger(self, entry: discord.AuditLogEntry):
"""This method automatically logs moderations done by users manually ("right clicks")."""
if entry.user.bot or entry.target.bot and await self.config.ignore_other_bots() is True:
return
if await self.config.ignore_other_bots() is True:
if entry.user.bot or entry.target.bot:
return
duration = "NULL"
if entry.reason:
reason = entry.reason + " (This action was performed without the bot.)"
@ -171,6 +172,25 @@ class Moderation(commands.Cog):
database.close()
logging.debug("MySQL row inserted into %s_moderation!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason)
@commands.hybrid_command(name="mute", aliases=['timeout'])
@commands.mod_or_permissions(discord.Permissions.moderate_members)
async def mute(self, ctx: commands.Context, target: discord.Member, duration: str, reason: str):
"""Mute a user."""
try:
parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True)
except ValueError:
await ctx.message.reply(f"Please provide a valid duration!\nSee `{ctx.prefix}tdc`")
return
await target.timeout(parsed_time)
response = await ctx.send(content=f"{target.mention} has been timed out for {str(parsed_time)}!\n**Reason** - `{reason}`")
try:
embed = discord.Embed(title="Timed Out", description=f"You have been timed out for `{str(parsed_time)}` in {ctx.guild.name}.", color=await self.bot.get_embed_color(None))
embed.add_field(name='Reason', value=f"`{reason}`")
await target.send(embed=embed)
except discord.errors.HTTPException:
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
self.mysql_log(ctx.guild.id, ctx.author.id, 'TIMEOUT', target.id, parsed_time, reason)
@commands.group(autohelp=True)
@checks.admin()
async def moderationset(self, ctx: commands.Context):