diff --git a/commands.py b/commands.py index 5fede55..cc8c5c9 100644 --- a/commands.py +++ b/commands.py @@ -5,29 +5,13 @@ import aiosqlite import os import sys import subprocess -from gdpr import check_consent, give_consent, revoke_consent +from gdpr import check_consent class ModCommands(commands.Cog): def __init__(self, bot): self.bot = bot - @app_commands.command(name="consent", - description="Give consent to store data") - async def consent(self, interaction: discord.Interaction): - await give_consent(interaction.user.id) - await interaction.response.send_message( - "Consent given to store your data." - ) - - @app_commands.command(name="revoke_consent", - description="Revoke consent to store data") - async def revoke_consent(self, interaction: discord.Interaction): - await revoke_consent(interaction.user.id) - await interaction.response.send_message( - "Consent revoked and your data has been deleted." - ) - @app_commands.command(name="addnote", description="Add a note to a user and optionally " "add strikes") @@ -49,8 +33,8 @@ class ModCommands(commands.Cog): notes = row[0] + "\n" + note current_strikes = row[1] + strikes await db.execute( - "UPDATE user_notes SET notes = ?," - "strikes = ? WHERE user_id = ?", + "UPDATE user_notes SET notes = ?, strikes = ? " + "WHERE user_id = ?", (notes, current_strikes, user.id) ) else: diff --git a/gdpr_commands.py b/gdpr_commands.py new file mode 100644 index 0000000..78c60b4 --- /dev/null +++ b/gdpr_commands.py @@ -0,0 +1,67 @@ +import discord +from discord import app_commands +from discord.ext import commands +import aiosqlite +from gdpr import check_consent, give_consent, revoke_consent + + +class GDPRCommands(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @app_commands.command(name="consent", + description="Give consent to store data") + async def consent(self, interaction: discord.Interaction): + await give_consent(interaction.user.id) + await interaction.response.send_message( + "Consent given to store your data." + ) + + @app_commands.command(name="revoke_consent", + description="Revoke consent to store data") + async def revoke_consent(self, interaction: discord.Interaction): + await revoke_consent(interaction.user.id) + await interaction.response.send_message( + "Consent revoked and your data has been deleted." + ) + + @app_commands.command(name="privacy_policy", + description="View the privacy policy") + async def privacy_policy(self, interaction: discord.Interaction): + privacy_text = ( + "Privacy Policy:\n" + "We collect and store data to provide better services. The data " + "includes:\n" + "- User ID\n" + "- Notes and Strikes added by moderators\n" + "Data is stored securely and only accessible by authorized " + "personnel.\n" + "You can revoke consent at any time by using the /revoke_consent " + "command.\n" + "For more details, visit our [website](https://example.com/privacy)." # noqa: E501 + ) + await interaction.response.send_message(privacy_text) + + @app_commands.command(name="get_my_data", + description="Get a copy of your data") + async def get_my_data(self, interaction: discord.Interaction): + user_id = interaction.user.id + async with aiosqlite.connect("ariella.db") as db: + cursor = await db.execute( + "SELECT notes, strikes FROM user_notes WHERE user_id = ?", + (user_id,) + ) + row = await cursor.fetchone() + if row: + notes, strikes = row + data_text = f"Your data:\nNotes: {notes}\nStrikes: {strikes}" + await interaction.user.send(data_text) + await interaction.response.send_message( + "Your data has been sent to you privately." + ) + else: + await interaction.response.send_message("No data found for you.") # noqa: E501 + + +async def setup(bot): + await bot.add_cog(GDPRCommands(bot)) diff --git a/main.py b/main.py index 6605b10..f90f1a1 100644 --- a/main.py +++ b/main.py @@ -9,8 +9,8 @@ from dotenv import load_dotenv load_dotenv() -GUILD_ID = int(os.getenv('GUILD_ID')) TOKEN = os.getenv('DISCORD_TOKEN') +GUILD_ID = int(os.getenv('GUILD_ID')) intents = discord.Intents.default() intents.message_content = True @@ -19,10 +19,11 @@ intents.members = True class Ariella(commands.Bot): def __init__(self): - super().__init__(command_prefix='!', intents=intents) + super().__init__(intents=intents) async def setup_hook(self): await self.load_extension('commands') + await self.load_extension('gdpr_commands') self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID)) await self.tree.sync(guild=discord.Object(id=GUILD_ID)) diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..325ed88 --- /dev/null +++ b/sample.env @@ -0,0 +1,2 @@ +DISCORD_TOKEN = "ADD YOUR TOKEN HERE" +GUILD_ID = "ADD YOUR GUILD ID HERE" \ No newline at end of file