Add abstaining from voting.
This commit is contained in:
+16
-5
@@ -6,13 +6,12 @@ from typing import List
|
||||
|
||||
import nextcord
|
||||
from nextcord import SelectOption
|
||||
from nextcord.ext import commands
|
||||
from nextcord.interactions import Interaction
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import exc, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from config import DakinyConfig, ElectionCycle
|
||||
from database_setup.sql_data_classes import CouncilMembers, ElectionInformation, engine
|
||||
from config import DakinyConfig
|
||||
from database_setup.sql_data_classes import CouncilMembers, ElectionInformation, Votes, engine
|
||||
from utils import build_votes_str, get_election_cycle_name
|
||||
|
||||
|
||||
@@ -33,7 +32,12 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
ElectionInformation.ElectionCycle == election_name
|
||||
)
|
||||
vote_msg_id = session.scalar(stmt)
|
||||
|
||||
if self.values[0] == "Abstain":
|
||||
voted_for = None
|
||||
else:
|
||||
voted_for = int(self.values[0])
|
||||
|
||||
new_vote = Votes(ElectionCycle=election_name, VoterId=interaction.user.id, VotedForId=voted_for)
|
||||
|
||||
try:
|
||||
@@ -54,7 +58,13 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
vote_message_str = build_votes_str(self.config)
|
||||
vote_msg = await interaction.channel.fetch_message(vote_msg_id)
|
||||
await vote_msg.edit(content=vote_message_str)
|
||||
await interaction.edit(content=f"You have voted for <@{self.values[0]}>", view=None)
|
||||
|
||||
if voted_for is not None:
|
||||
msg = f"You have voted for <@{voted_for}>"
|
||||
else:
|
||||
msg = "You have abstained from voting."
|
||||
|
||||
await interaction.edit(content=msg, view=None)
|
||||
|
||||
|
||||
class VoteView(nextcord.ui.View):
|
||||
@@ -98,6 +108,7 @@ class VoteView(nextcord.ui.View):
|
||||
)
|
||||
for nominee in session.scalars(stmt)
|
||||
]
|
||||
options.append(SelectOption(label="Abstain ☑️" if voted_for is None else "Abstain", value="Abstain"))
|
||||
|
||||
view = nextcord.ui.View()
|
||||
view.add_item(VoteSelect(options=options, config=self.config))
|
||||
|
||||
Reference in New Issue
Block a user