Updated the consent to allow opt-in or out
This commit is contained in:
@@ -12,22 +12,27 @@ class ConsentView(View):
|
||||
@discord.ui.button(label="Consent to Data Storage", style=discord.ButtonStyle.green)
|
||||
async def confirm(self, interaction: discord.Interaction, button: Button):
|
||||
self.value = True
|
||||
await interaction.response.send_message("Thank you for consenting to data storage!", ephemeral=True)
|
||||
await store_user_consent(interaction.user.id)
|
||||
await interaction.response.edit_message(content="Thank you for consenting to data storage!", view=None)
|
||||
self.stop()
|
||||
|
||||
@discord.ui.button(label="Decline", style=discord.ButtonStyle.grey)
|
||||
@discord.ui.button(label="Decline Data Storage", style=discord.ButtonStyle.grey)
|
||||
async def cancel(self, interaction: discord.Interaction, button: Button):
|
||||
self.value = False
|
||||
await interaction.response.send_message("You have declined data storage. You cannot use this bot without consenting.", ephemeral=True)
|
||||
await interaction.response.edit_message(content="You have declined data storage. You cannot use this bot without consenting.", view=None)
|
||||
self.stop()
|
||||
|
||||
|
||||
async def check_user_consent(user_id):
|
||||
"""Check if the user has given consent to data storage."""
|
||||
"""Check if the user has given consent to data storage, default to True."""
|
||||
async with aiosqlite.connect(DATABASE) as db:
|
||||
cursor = await db.execute("SELECT consent_given FROM user_consents WHERE user_id = ?", (user_id,))
|
||||
result = await cursor.fetchone()
|
||||
return result[0] if result else False
|
||||
if result is None:
|
||||
# Assume consent given if no record exists
|
||||
return True
|
||||
return result[0]
|
||||
|
||||
|
||||
async def store_user_consent(user_id):
|
||||
"""Store the user's consent to data storage."""
|
||||
@@ -35,3 +40,8 @@ async def store_user_consent(user_id):
|
||||
await db.execute("INSERT OR REPLACE INTO user_consents (user_id, consent_given) VALUES (?, TRUE)", (user_id,))
|
||||
await db.commit()
|
||||
|
||||
async def revoke_user_consent(user_id):
|
||||
"""Revoke the user's consent to data storage."""
|
||||
async with aiosqlite.connect(DATABASE) as db:
|
||||
await db.execute("UPDATE user_consents SET consent_given = FALSE WHERE user_id = ?", (user_id,))
|
||||
await db.commit()
|
Reference in New Issue
Block a user