diff --git a/moderation/moderation.py b/moderation/moderation.py index 4a426c3..91ee486 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -23,6 +23,34 @@ class Moderation(commands.Cog): """Custom moderation cog. Developed by SeaswimmerTheFsh.""" + async def red_delete_data_for_user(self, *, requester, user_id: int): + if requester == "discord_deleted_user": + await self.config.user_from_id(user_id).clear() + + database = await self.connect() + cursor = database.cursor() + + cursor.execute("SHOW TABLES;") + tables = [table[0] for table in cursor.fetchall()] + + condition = "target_id = %s OR moderator_id = %s;" + + for table in tables: + delete_query = f"DELETE FROM {table[0]} WHERE {condition}" + cursor.execute(delete_query, (user_id, user_id)) + + database.commit() + cursor.close() + database.close() + if requester == "owner": + await self.config.user_from_id(user_id).clear() + if requester == "user": + await self.config.user_from_id(user_id).clear() + if requester == "user_strict": + await self.config.user_from_id(user_id).clear() + else: + self.logger.warning("Invalid requester passed to red_delete_data_for_user: %s", requester) + def __init__(self, bot): self.bot = bot self.config = Config.get_conf(self, identifier=481923957134912)