From 9b68892b67fb0b0ef94ff43a6205e064d29da155 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 13 Dec 2023 03:06:26 -0500 Subject: [PATCH] bunch of goofy/broken changes --- moderation/moderation.py | 76 +++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 092ad3a..8c04671 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -143,6 +143,7 @@ class Moderation(commands.Cog): moderation_type LONGTEXT NOT NULL, target_id LONGTEXT NOT NULL, moderator_id LONGTEXT NOT NULL, + role_id LONGTEXT, duration LONGTEXT, end_timestamp INT, reason LONGTEXT, @@ -161,10 +162,10 @@ class Moderation(commands.Cog): cursor.execute(index_query_3, (guild.id,)) insert_query = f""" INSERT INTO `moderation_{guild.id}` - (moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) + (moderation_id, timestamp, moderation_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """ - insert_values = (0, 0, "NULL", 0, 0, "NULL", 0, "NULL", 0, "NULL", "NULL", 0) + insert_values = (0, 0, "NULL", 0, 0, 0, "NULL", 0, "NULL", 0, "NULL", "NULL", 0) cursor.execute(insert_query, insert_values) database.commit() self.logger.info("MySQL Table (moderation_%s) created for %s (%s)", guild.id, guild.name, guild.id) @@ -193,7 +194,7 @@ class Moderation(commands.Cog): return permission return False - async def mysql_log(self, guild_id: str, author_id: str, moderation_type: str, target_id: int, duration, reason: str): + async def mysql_log(self, guild_id: str, author_id: str, moderation_type: str, target_id: int, role_id: int, duration, reason: str): timestamp = int(time.time()) if duration != "NULL": end_timedelta = datetime.fromtimestamp(timestamp) + duration @@ -203,12 +204,12 @@ class Moderation(commands.Cog): database = await self.connect() cursor = database.cursor() moderation_id = await self.get_next_case_number(guild_id=guild_id, cursor=cursor) - sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" - val = (moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, f"{reason}", 0, "NULL", "NULL", 0) + sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" + val = (moderation_id, timestamp, moderation_type, target_id, author_id, role_id, duration, end_timestamp, f"{reason}", 0, "NULL", "NULL", 0) cursor.execute(sql, val) database.commit() database.close() - self.logger.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL, NULL, 0", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason) + self.logger.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, %s, 0, NULL, NULL, 0", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, role_id, duration, end_timestamp, reason) return moderation_id async def get_next_case_number(self, guild_id: str, cursor = None): @@ -226,13 +227,14 @@ class Moderation(commands.Cog): "moderation_type": result[2], "target_id": result[3], "moderator_id": result[4], - "duration": result[5], - "end_timestamp": result[6], - "reason": result[7], - "resolved": result[8], - "resolved_by": result[9], - "resolve_reason": result[10], - "expired": result[11] + "role_id": result[5], + "duration": result[6], + "end_timestamp": result[7], + "reason": result[8], + "resolved": result[9], + "resolved_by": result[10], + "resolve_reason": result[11], + "expired": result[12] } return case @@ -299,7 +301,7 @@ class Moderation(commands.Cog): target_user = await self.fetch_user_dict(interaction, case_dict['target_id']) moderator_user = await self.fetch_user_dict(interaction, case_dict['moderator_id']) target_name = f"`{target_user['name']}`" if target_user['discriminator'] == "0" else f"`{target_user['name']}#{target_user['discriminator']}`" - moderator_name = moderator_user['name'] if moderator_user['discriminator'] == "0" else f"{moderator_user['name']}#{moderator_user['discriminator']}" + moderator_name = f"`{moderator_user['name']}`" if moderator_user['discriminator'] == "0" else f"`{moderator_user['name']}#{moderator_user['discriminator']}`" embed = discord.Embed(title=f"📕 Case #{case_dict['moderation_id']}", color=await self.bot.get_embed_color(None)) embed.description = f"**Type:** {str.title(case_dict['moderation_type'])}\n**Target:** {target_name} ({target_user['id']})\n**Moderator:** {moderator_name} ({moderator_user['id']})\n**Resolved:** {bool(case_dict['resolved'])}\n**Timestamp:** | " if case_dict['duration'] != 'NULL': @@ -309,7 +311,7 @@ class Moderation(commands.Cog): embed.add_field(name='Reason', value=f"```{case_dict['reason']}```", inline=False) if case_dict['resolved'] == 1: resolved_user = await self.fetch_user_dict(interaction, case_dict['resolved_by']) - resolved_name = resolved_user['name'] if resolved_user['discriminator'] == "0" else f"{resolved_user['name']}#{resolved_user['discriminator']}" + resolved_name = f"`{resolved_user['name']}`" if resolved_user['discriminator'] == "0" else f"`{resolved_user['name']}#{resolved_user['discriminator']}`" embed.add_field(name='Resolve Reason', value=f"Resolved by {resolved_name} ({resolved_user['id']}) for:\n```{case_dict['resolve_reason']}```", inline=False) return embed @@ -397,7 +399,7 @@ class Moderation(commands.Cog): await target.send(embed=embed) except discord.errors.HTTPException: pass - moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'NOTE', target.id, 'NULL', reason) + moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'NOTE', target.id, 0, 'NULL', reason) await self.log(interaction, moderation_id) @app_commands.command(name="warn") @@ -429,7 +431,7 @@ class Moderation(commands.Cog): await target.send(embed=embed) except discord.errors.HTTPException: pass - moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'WARN', target.id, 'NULL', reason) + moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'WARN', target.id, 0, 'NULL', reason) await self.log(interaction, moderation_id) @app_commands.command(name="mute") @@ -479,7 +481,7 @@ class Moderation(commands.Cog): await target.send(embed=embed) except discord.errors.HTTPException: pass - moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'MUTE', target.id, parsed_time, reason) + moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'MUTE', target.id, 0, parsed_time, reason) await self.log(interaction, moderation_id) @app_commands.command(name="unmute") @@ -523,7 +525,7 @@ class Moderation(commands.Cog): await target.send(embed=embed) except discord.errors.HTTPException: pass - moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNMUTE', target.id, 'NULL', reason) + moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNMUTE', target.id, 0, 'NULL', reason) await self.log(interaction, moderation_id) @app_commands.command(name="kick") @@ -560,7 +562,7 @@ class Moderation(commands.Cog): except discord.errors.HTTPException: pass await target.kick(f"Kicked by {interaction.user.id} for: {reason}") - moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'KICK', target.id, 'NULL', reason) + moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'KICK', target.id, 0, 'NULL', reason) await self.log(interaction, moderation_id) @app_commands.command(name="ban") @@ -630,7 +632,7 @@ class Moderation(commands.Cog): except discord.errors.HTTPException: pass await interaction.guild.ban(target, reason=f"Banned by {interaction.user.id} for: {reason}", delete_message_seconds=delete_messages) - moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'BAN', target.id, 'NULL', reason) + moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'BAN', target.id, 0, 'NULL', reason) await self.log(interaction, moderation_id) @app_commands.command(name="unban") @@ -676,11 +678,11 @@ class Moderation(commands.Cog): await target.send(embed=embed) except discord.errors.HTTPException: pass - moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNBAN', target.id, 'NULL', reason) + moderation_id = await self.mysql_log(interaction.guild.id, interaction.user.id, 'UNBAN', target.id, 0, 'NULL', reason) await self.log(interaction, moderation_id) @app_commands.command(name="history") - async def history(self, interaction: discord.Interaction, target: discord.User = None, moderator: discord.User = None, pagesize: app_commands.Range[int, 1, 25] = 5, page: int = 1, epheremal: bool = False): + async def history(self, interaction: discord.Interaction, target: discord.User = None, moderator: discord.User = None, pagesize: app_commands.Range[int, 1, 25] = 5, page: int = 1, ephemeral: bool = False): """List previous infractions. Parameters @@ -749,7 +751,7 @@ class Moderation(commands.Cog): if bool(case['resolved']): field_value = field_value + "\n**Resolved:** True" embed.add_field(name=field_name, value=field_value, inline=False) - await interaction.response.send_message(embed=embed, ephemeral=epheremal) + await interaction.response.send_message(embed=embed, ephemeral=ephemeral) @app_commands.command(name="resolve") async def resolve(self, interaction: discord.Interaction, case_number: int, reason: str = None): @@ -974,6 +976,30 @@ class Moderation(commands.Cog): send = f"Configuration changed:\n{message}" await interaction.response.send_message(send, ephemeral=True) + @moderationset.group(autohelp=True) + @checks.admin() + async def moderationset_import(self, ctx: commands.Context): + """Import moderations from other bots.""" + + @moderationset_import.command(name="galacticbot") + @checks.admin() + async def moderationset_import_galacticbot(self, ctx: commands.Context): + """Import moderations from GalacticBot. **UNFINISHED!**""" + await ctx.send("Are you sure you want to import GalacticBot moderations? This will overwrite any moderations that already exist in the database.", view=self.GalacticBotImportButtons(60)) + + class GalacticBotImportButtons(discord.ui.View): + def __init__(self, timeout): + super().__init__() + self.config = Config.get_conf(None, cog_name='Moderation', identifier=481923957134912) + + @discord.ui.button(label="Yes", style=discord.ButtonStyle.success) + async def config_button(self, interaction: discord.Interaction, button: discord.ui.Button): # pylint: disable=unused-argument + await interaction.response.send_modal(Moderation.MySQLConfigModal(self.config)) + + @discord.ui.button(label="No", style=discord.ButtonStyle.danger) + async def config_button(self, interaction: discord.Interaction, button: discord.ui.Button): # pylint: disable=unused-argument + await interaction.response.send_modal(Moderation.MySQLConfigModal(self.config)) + @commands.command(aliases=["tdc"]) async def timedeltaconvert(self, ctx: commands.Context, *, duration: str): """This command converts a duration to a [`timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta) Python object.