Pull the vote count message out of vote start.

Make its own builder function in utils.
This commit is contained in:
2023-11-03 11:55:21 -04:00
parent a5ef579767
commit fa3284b9e3
3 changed files with 40 additions and 27 deletions
+39
View File
@@ -4,7 +4,11 @@ File contains util functions.
from datetime import datetime
from sqlalchemy import select
from sqlalchemy.orm import Session
from config import DakinyConfig
from database_setup.sql_data_classes import CouncilMembers, Votes, engine
def get_datetime(day: str) -> datetime:
@@ -62,3 +66,38 @@ def get_current_cycle(config: DakinyConfig) -> int:
return cycle
return -1
def build_votes_str(config: DakinyConfig) -> str:
"""
Creates a string that contains all nominees and their votes to be sent as a discord message.
Args:
config (DakinyConfig): Daking config object
Returns:
str: String that contains all nominees and their votes.
"""
votes: dict[int, int] = {}
with Session(engine) as session:
stmt = select(CouncilMembers).where(CouncilMembers.ElectionCycle == get_election_cycle_name(config))
for nominee in session.scalars(stmt):
votes[nominee.MemberId] = 0
stmt = select(Votes).where(Votes.ElectionCycle == get_election_cycle_name(config))
for vote in session.scalars(stmt):
votes[vote.VotedForId] += 1
votes_str: str = "===================="
for user_id, num_votes in votes.items():
votes_str += f"<@{user_id}>: "
for num in range(num_votes):
votes_str += "☑️"
votes_str += "\n"
return votes_str