Changing the project to being called Nessa now
This commit is contained in:
63
nessa/nessa.py
Normal file
63
nessa/nessa.py
Normal file
@ -0,0 +1,63 @@
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from .commands import NessaTracker
|
||||
from .consent import ConsentView, check_user_consent, store_user_consent
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
GUILD_ID = int(os.getenv("DISCORD_GUILD_ID"))
|
||||
OWNER_ID = int(os.getenv("AUTHORIZED_USER_ID"))
|
||||
|
||||
class Nessa(discord.Client):
|
||||
def __init__(self):
|
||||
super().__init__(intents=discord.Intents.default())
|
||||
self.tree = app_commands.CommandTree(self)
|
||||
|
||||
async def setup_hook(self):
|
||||
self.tree.add_command(NessaTracker())
|
||||
self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID))
|
||||
await self.tree.sync(guild=discord.Object(id=GUILD_ID))
|
||||
|
||||
@self.tree.command(name="shutdown", description="Shut down Nessa", guild=discord.Object(id=GUILD_ID))
|
||||
async def shutdown(interaction: discord.Interaction):
|
||||
if interaction.user.id == OWNER_ID:
|
||||
await interaction.response.send_message("Night, Night. Shutting down...")
|
||||
await self.close()
|
||||
else:
|
||||
await interaction.response.send_message("Hey! I don't know you! You don't have permission to use this command. Only the owner can do that.", ephemeral=True)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f"Logged on as {self.user}!")
|
||||
self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID))
|
||||
await self.tree.sync(guild=discord.Object(id=GUILD_ID))
|
||||
|
||||
async def on_interaction(self, interaction: discord.Interaction):
|
||||
if interaction.type == discord.InteractionType.application_command:
|
||||
# First, check if the user has consented to data storage.
|
||||
consented = await check_user_consent(interaction.user.id)
|
||||
|
||||
if not consented:
|
||||
# If there is no consent, show the consent dialog,
|
||||
# unless the command is to opt-out, which should be accessible without prior consent.
|
||||
if interaction.command.name == 'opt-out':
|
||||
# Allow users to opt-out directly if they mistakenly initiated any command.
|
||||
return
|
||||
view = ConsentView()
|
||||
await interaction.response.send_message(
|
||||
"By using the services I, Nessa, provide, you consent to the storage of your data necessary for functionality. Please confirm your consent. See /nessa consent privacy-policy for more details.",
|
||||
view=view,
|
||||
ephemeral=True
|
||||
)
|
||||
await view.wait()
|
||||
if view.value:
|
||||
await store_user_consent(interaction.user.id)
|
||||
else:
|
||||
await interaction.followup.send("Whoops! You have to give me your okay to do store your data before you can use my services!", ephemeral=True)
|
||||
return # Stop processing if they do not consent
|
||||
|
||||
# For opt-in command, check if they're trying to opt-in after opting out.
|
||||
if interaction.command.name == 'opt-in':
|
||||
if consented:
|
||||
await interaction.response.send_message("Hey! Thanks, but you've already opted in.", ephemeral=True)
|
||||
return
|
Reference in New Issue
Block a user