Add nominees and voting total to voting message.
This commit is contained in:
@@ -12,3 +12,7 @@ Votes for multiple candidates from the same person will not be counted.
|
||||
|
||||
RS3 Clan Members
|
||||
OSRS Clan Members
|
||||
|
||||
====================
|
||||
Clan nominees:
|
||||
{clan_nominees}
|
||||
@@ -10,7 +10,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from classes.nominate_views import NominateView
|
||||
from config import DakinyConfig
|
||||
from database_setup.sql_data_classes import ElectionInformation, engine
|
||||
from database_setup.sql_data_classes import CouncilMembers, ElectionInformation, Votes, engine
|
||||
from utils import get_datetime, get_election_cycle_name
|
||||
|
||||
|
||||
@@ -121,11 +121,33 @@ class ElectionCycle:
|
||||
message = file.read()
|
||||
vote_end: datetime = get_datetime(self.config.election_cycles[self.cycle].voting_end)
|
||||
|
||||
votes: dict[int, int] = {}
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(CouncilMembers).where(ElectionCycle == get_election_cycle_name(self.config))
|
||||
|
||||
for nominee in session.scalars(stmt):
|
||||
votes[nominee.MemberId] = 0
|
||||
|
||||
stmt = select(Votes).where(ElectionCycle == get_election_cycle_name(self.config))
|
||||
|
||||
for vote in session.scalars(stmt):
|
||||
votes[vote.VotedForId] += 1
|
||||
|
||||
nominees_str: str = ""
|
||||
for user_id, num_votes in votes.items():
|
||||
nominees_str += f"<@{user_id}>: "
|
||||
|
||||
for num in range(num_votes):
|
||||
nominees_str += "☑️"
|
||||
nominees_str += "\n"
|
||||
|
||||
return message.format(
|
||||
clan_member_id=self.config.params.clan_member_role_id,
|
||||
voting_emote_id=self.config.params.voting_emote_id,
|
||||
voting_end=vote_end.strftime("%B %d"),
|
||||
voting_end_day=vote_end.strftime("%A"),
|
||||
clan_nominees=nominees_str,
|
||||
)
|
||||
|
||||
async def check_date(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user