From 2f75f0cdcbe3b4958a4c14ec4852742d7145a573 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Fri, 22 Dec 2023 21:56:29 -0500 Subject: [PATCH] Finish up presence auto complete function. --- cogs/commands/remove.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cogs/commands/remove.py b/cogs/commands/remove.py index 2fedef2..aab8bb6 100644 --- a/cogs/commands/remove.py +++ b/cogs/commands/remove.py @@ -7,12 +7,7 @@ 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, -) +from database_setup.sql_data_classes import Presences, engine class RemoveCog(commands.Cog, name="View Commands"): @@ -56,6 +51,7 @@ class RemoveCog(commands.Cog, name="View Commands"): ): """ Collects all presences that start with the presence string. + Sends autocomplete dict {Presence Name, Presence Id} Args: interaction (nextcord.Interaction): Interaction with command. @@ -64,16 +60,20 @@ class RemoveCog(commands.Cog, name="View Commands"): with Session(engine) as session: stmt = select(Presences) - presences = session.scalars(stmt) + presences_dict: "dict[str,str]" = { + pres.Presence: str(pres.Id) for pres in session.scalars(stmt) + } # if empty compare string - if not election_name: - await interaction.response.send_autocomplete(elections[:25]) + if not presence: + await interaction.response.send_autocomplete( + dict(list(presences_dict.items())[:25]) + ) return - autofilled_presences: "list[str]" = [ - election - for election in elections - if election.lower().startswith(election_name.lower()) - ] + autofilled_presences: "dict[str,str]" = { + pres: pres_id + for pres, pres_id in presences_dict.items() + if presence.lower() in pres.lower() + } await interaction.response.send_autocomplete(autofilled_presences[:25])