feat(moderation): expiry_handler now messages users who are unbanned (or attempts to)
Some checks failed
Pylint / Pylint (push) Failing after 1m13s

This commit is contained in:
Seaswimmer 2023-10-05 16:26:45 -04:00
parent 6bfd110b35
commit 696165239f
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -393,7 +393,7 @@ class Moderation(commands.Cog):
embed.description = f"**Type:** {str.title(case['moderation_type'])}\n**Target:** {target_name} ({target.id})\n**Moderator:** {moderator_name} ({moderator.id})\n**Resolved:** {bool(case['resolved'])}\n**Timestamp:** <t:{case['timestamp']}> | <t:{case['timestamp']}:R>" embed.description = f"**Type:** {str.title(case['moderation_type'])}\n**Target:** {target_name} ({target.id})\n**Moderator:** {moderator_name} ({moderator.id})\n**Resolved:** {bool(case['resolved'])}\n**Timestamp:** <t:{case['timestamp']}> | <t:{case['timestamp']}:R>"
if case['duration'] != 'NULL': if case['duration'] != 'NULL':
td = timedelta(**{unit: int(val) for unit, val in zip(["hours", "minutes", "seconds"], case["duration"].split(":"))}) td = timedelta(**{unit: int(val) for unit, val in zip(["hours", "minutes", "seconds"], case["duration"].split(":"))})
embed.description = embed.description + f"\n**Duration:** {humanize.precisedelta(td)}\n**Expired:** {bool(case['expired'])}" embed.description = embed.description + f"\n**Duration:** {humanize.precisedelta(td)} | <t:{case['end_timestamp']}:R>\n**Expired:** {bool(case['expired'])}"
embed.add_field(name='Reason', value=f"```{case['reason']}```", inline=False) embed.add_field(name='Reason', value=f"```{case['reason']}```", inline=False)
if case['resolved'] == 1: if case['resolved'] == 1:
embed.add_field(name='Resolve Reason', value=f"```{case['resolve_reason']}```", inline=False) embed.add_field(name='Resolve Reason', value=f"```{case['resolve_reason']}```", inline=False)
@ -417,8 +417,13 @@ class Moderation(commands.Cog):
target_ids = [row[0] for row in result] target_ids = [row[0] for row in result]
moderation_ids = [row[1] for row in result] moderation_ids = [row[1] for row in result]
for target_id, moderation_id in zip(target_ids, moderation_ids): for target_id, moderation_id in zip(target_ids, moderation_ids):
user = await self.bot.fetch_user(target_id) user: discord.User = await self.bot.fetch_user(target_id)
await guild.unban(user, reason=f"Automatic unban from case #{moderation_id}") await guild.unban(user, reason=f"Automatic unban from case #{moderation_id}")
embed = await self.embed_factory('message', guild, f'Automatic unban from case #{moderation_id}', 'unbanned')
try:
await user.send(embed=embed)
except discord.errors.HTTPException:
pass
expiry_query = f"UPDATE `{db}`.`moderation_{guild.id}` SET expired = 1 WHERE (end_timestamp != 0 AND end_timestamp <= %s AND expired = 0) OR (expired = 0 AND resolved = 1)" expiry_query = f"UPDATE `{db}`.`moderation_{guild.id}` SET expired = 1 WHERE (end_timestamp != 0 AND end_timestamp <= %s AND expired = 0) OR (expired = 0 AND resolved = 1)"
cursor.execute(expiry_query, (time.time(),)) cursor.execute(expiry_query, (time.time(),))
database.commit() database.commit()