Finish up presence auto complete function.
This commit is contained in:
+14
-14
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user