From 39746123f15847e25f34087ba9831527ddd6c8ee Mon Sep 17 00:00:00 2001 From: imcompiling Date: Fri, 22 Dec 2023 21:23:29 -0500 Subject: [PATCH] Add beginning of remove presence. --- cogs/commands/remove.py | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 cogs/commands/remove.py diff --git a/cogs/commands/remove.py b/cogs/commands/remove.py new file mode 100644 index 0000000..2fedef2 --- /dev/null +++ b/cogs/commands/remove.py @@ -0,0 +1,79 @@ +""" +Commands for removing information in the database. +""" + +import nextcord +from nextcord.ext import commands +from sqlalchemy import select +from sqlalchemy.orm import Session + +from database_setup.sql_data_classes import ( + ElectionInformation, + Presences, + Votes, + engine, +) + + +class RemoveCog(commands.Cog, name="View Commands"): + """ + Holds the view commands. + """ + + def __init__(self) -> None: + """ + Default constructor for RemoveCog class. Does nothing. + """ + + @nextcord.slash_command( + guild_ids=[1000247361639030804], + default_member_permissions=nextcord.Permissions(administrator=True), + ) # TODO remove guild ids + async def remove(self, interaction: nextcord.Interaction): + """ + Parent slash command for set. Never called. + """ + + @remove.subcommand(description="Remove a presence from the database.") + async def presence( + self, + interaction: nextcord.Interaction, + presence: str = nextcord.SlashOption( + description="The presence to remove", required=True + ), + ): + """ + _summary_ + + Args: + interaction (nextcord.Interaction): Interaction that invoked the command. + presence (str): Is SlashOption. The presence to remove. + """ + + @remove.on_autocomplete("presence") + async def election_autocomplete( + self, interaction: nextcord.Interaction, presence: str + ): + """ + Collects all presences that start with the presence string. + + Args: + interaction (nextcord.Interaction): Interaction with command. + presence (str): String to run autocomplete on. + """ + + with Session(engine) as session: + stmt = select(Presences) + presences = session.scalars(stmt) + + # if empty compare string + if not election_name: + await interaction.response.send_autocomplete(elections[:25]) + return + + autofilled_presences: "list[str]" = [ + election + for election in elections + if election.lower().startswith(election_name.lower()) + ] + await interaction.response.send_autocomplete(autofilled_presences[:25])