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 import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from database_setup.sql_data_classes import (
|
from database_setup.sql_data_classes import Presences, engine
|
||||||
ElectionInformation,
|
|
||||||
Presences,
|
|
||||||
Votes,
|
|
||||||
engine,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveCog(commands.Cog, name="View Commands"):
|
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.
|
Collects all presences that start with the presence string.
|
||||||
|
Sends autocomplete dict {Presence Name, Presence Id}
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with command.
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
@@ -64,16 +60,20 @@ class RemoveCog(commands.Cog, name="View Commands"):
|
|||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Presences)
|
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 empty compare string
|
||||||
if not election_name:
|
if not presence:
|
||||||
await interaction.response.send_autocomplete(elections[:25])
|
await interaction.response.send_autocomplete(
|
||||||
|
dict(list(presences_dict.items())[:25])
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
autofilled_presences: "list[str]" = [
|
autofilled_presences: "dict[str,str]" = {
|
||||||
election
|
pres: pres_id
|
||||||
for election in elections
|
for pres, pres_id in presences_dict.items()
|
||||||
if election.lower().startswith(election_name.lower())
|
if presence.lower() in pres.lower()
|
||||||
]
|
}
|
||||||
await interaction.response.send_autocomplete(autofilled_presences[:25])
|
await interaction.response.send_autocomplete(autofilled_presences[:25])
|
||||||
|
|||||||
Reference in New Issue
Block a user