Scalars doesn't return None if the thing doesn't exists while scalar does.
This commit is contained in:
+24
-23
@@ -49,22 +49,23 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
stmt = select(Votes).where(Votes.ElectionCycle == election_name)
|
stmt = select(Votes).where(Votes.ElectionCycle == election_name)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
try:
|
# Check if election exists.
|
||||||
votes = session.scalars(stmt)
|
if session.scalar(stmt) is None:
|
||||||
content = ""
|
|
||||||
|
|
||||||
for vote in votes:
|
|
||||||
content += (
|
|
||||||
f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>.\n"
|
|
||||||
if vote.VotedForId is not None
|
|
||||||
else f"<@{vote.VoterId}> abstained from voted.\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
await interaction.response.send_message(content=content, ephemeral=True)
|
|
||||||
except:
|
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
f"Invalid election: {election_name}.", ephemeral=True
|
f"Invalid election: {election_name}.", ephemeral=True
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
votes = session.scalars(stmt)
|
||||||
|
content = ""
|
||||||
|
for vote in votes:
|
||||||
|
content += (
|
||||||
|
f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>.\n"
|
||||||
|
if vote.VotedForId is not None
|
||||||
|
else f"<@{vote.VoterId}> abstained from voted.\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
await interaction.response.send_message(content=content, ephemeral=True)
|
||||||
|
|
||||||
@votes.on_autocomplete("election_name")
|
@votes.on_autocomplete("election_name")
|
||||||
async def election_autocomplete(
|
async def election_autocomplete(
|
||||||
@@ -82,14 +83,14 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
stmt = select(ElectionInformation.ElectionCycle)
|
stmt = select(ElectionInformation.ElectionCycle)
|
||||||
elections = session.scalars(stmt)
|
elections = session.scalars(stmt)
|
||||||
|
|
||||||
# if empty compare string
|
# if empty compare string
|
||||||
if not election_name:
|
if not election_name:
|
||||||
await interaction.response.send_autocomplete(elections)
|
await interaction.response.send_autocomplete(elections)
|
||||||
return
|
return
|
||||||
|
|
||||||
autofilled_elections: "list[str]" = [
|
autofilled_elections: "list[str]" = [
|
||||||
election
|
election
|
||||||
for election in elections
|
for election in elections
|
||||||
if election.lower().startswith(election_name.lower())
|
if election.lower().startswith(election_name.lower())
|
||||||
]
|
]
|
||||||
await interaction.response.send_autocomplete(autofilled_elections[:25])
|
await interaction.response.send_autocomplete(autofilled_elections[:25])
|
||||||
|
|||||||
Reference in New Issue
Block a user