feat(moderation): added support for data deletion requests

This commit is contained in:
Seaswimmer 2023-12-14 19:04:27 -05:00
parent 1d9114e19b
commit 9380143d04
Signed by untrusted user: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -23,6 +23,34 @@ class Moderation(commands.Cog):
"""Custom moderation cog. """Custom moderation cog.
Developed by SeaswimmerTheFsh.""" 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): def __init__(self, bot):
self.bot = bot self.bot = bot
self.config = Config.get_conf(self, identifier=481923957134912) self.config = Config.get_conf(self, identifier=481923957134912)