Compare commits

...

2 commits

Author SHA1 Message Date
9f1d864b31
misc(moderation): changed all instances of timeout to mute
Some checks failed
Pylint / Pylint (push) Failing after 1m12s
2023-10-04 12:45:29 -04:00
57f49d8e42
feat(moderation): added timeout command 2023-10-04 12:44:21 -04:00

View file

@ -60,8 +60,9 @@ class Moderation(commands.Cog):
@commands.Cog.listener('on_audit_log_entry_create') @commands.Cog.listener('on_audit_log_entry_create')
async def autologger(self, entry: discord.AuditLogEntry): async def autologger(self, entry: discord.AuditLogEntry):
"""This method automatically logs moderations done by users manually ("right clicks").""" """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: if await self.config.ignore_other_bots() is True:
return if entry.user.bot or entry.target.bot:
return
duration = "NULL" duration = "NULL"
if entry.reason: if entry.reason:
reason = entry.reason + " (This action was performed without the bot.)" reason = entry.reason + " (This action was performed without the bot.)"
@ -79,9 +80,9 @@ class Moderation(commands.Cog):
duration_datetime = timed_out_until_aware - datetime.now(tz=timezone.utc) duration_datetime = timed_out_until_aware - datetime.now(tz=timezone.utc)
minutes = round(duration_datetime.total_seconds() / 60) minutes = round(duration_datetime.total_seconds() / 60)
duration = timedelta(minutes=minutes) duration = timedelta(minutes=minutes)
moderation_type = 'TIMEOUT' moderation_type = 'MUTE'
else: else:
moderation_type = 'UNTIMEOUT' moderation_type = 'UNMUTE'
else: else:
return return
await self.mysql_log(entry.guild.id, entry.user.id, moderation_type, entry.target.id, duration, reason) await self.mysql_log(entry.guild.id, entry.user.id, moderation_type, entry.target.id, duration, reason)
@ -171,6 +172,25 @@ class Moderation(commands.Cog):
database.close() 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) 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 muted for {str(parsed_time)}!\n**Reason** - `{reason}`")
try:
embed = discord.Embed(title="Muted", description=f"You have been muted 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, 'MUTE', target.id, parsed_time, reason)
@commands.group(autohelp=True) @commands.group(autohelp=True)
@checks.admin() @checks.admin()
async def moderationset(self, ctx: commands.Context): async def moderationset(self, ctx: commands.Context):