Files
Nessa/dolly/consent.py
2024-05-04 21:30:49 -04:00

38 lines
1.5 KiB
Python

import discord
from discord.ui import View, Button
import aiosqlite
DATABASE = "dolly.db"
class ConsentView(View):
def __init__(self):
super().__init__()
self.value = None
@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)
self.stop()
@discord.ui.button(label="Decline", 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)
self.stop()
async def check_user_consent(user_id):
"""Check if the user has given consent to data storage."""
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
async def store_user_consent(user_id):
"""Store the user's consent to data storage."""
async with aiosqlite.connect(DATABASE) as db:
await db.execute("INSERT OR REPLACE INTO user_consents (user_id, consent_given) VALUES (?, TRUE)", (user_id,))
await db.commit()