Finish up presence auto complete function.

This commit is contained in:
2023-12-22 21:56:29 -05:00
parent deb405f02b
commit 2f75f0cdcb
+14 -14
View File
@@ -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])