Break out repeated code into helper function.
This commit is contained in:
@@ -133,15 +133,81 @@ def build_votes_str(config: DakinyConfig) -> str:
|
|||||||
votes[vote.VotedForId] += 1
|
votes[vote.VotedForId] += 1
|
||||||
|
|
||||||
votes_str: str = "===================="
|
votes_str: str = "===================="
|
||||||
for user_id, num_votes in votes.items():
|
votes_str += user_vote_str(votes)
|
||||||
votes_str += f"\n<@{user_id}>: "
|
|
||||||
|
|
||||||
for num in range(num_votes):
|
|
||||||
votes_str += "☑️"
|
|
||||||
|
|
||||||
return votes_str
|
return votes_str
|
||||||
|
|
||||||
|
|
||||||
|
def build_highcouncil_votes_str(config: DakinyConfig) -> str:
|
||||||
|
"""
|
||||||
|
Creates a string that contains all high council 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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
cl_votes: dict[int, int] = {}
|
||||||
|
dm_votes: dict[int, int] = {}
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = select(CouncilMembers).where(
|
||||||
|
CouncilMembers.ElectionCycle == get_cl_election_name(config)
|
||||||
|
)
|
||||||
|
|
||||||
|
for nominee in session.scalars(stmt):
|
||||||
|
cl_votes[nominee.MemberId] = 0
|
||||||
|
|
||||||
|
stmt = select(Votes).where(
|
||||||
|
Votes.ElectionCycle == get_election_cycle_name(config)
|
||||||
|
)
|
||||||
|
|
||||||
|
for vote in session.scalars(stmt):
|
||||||
|
if vote.VotedForId is not None:
|
||||||
|
cl_votes[vote.VotedForId] += 1
|
||||||
|
|
||||||
|
stmt = select(CouncilMembers).where(
|
||||||
|
CouncilMembers.ElectionCycle == get_dm_election_name(config)
|
||||||
|
)
|
||||||
|
|
||||||
|
for nominee in session.scalars(stmt):
|
||||||
|
dm_votes[nominee.MemberId] = 0
|
||||||
|
|
||||||
|
stmt = select(Votes).where(
|
||||||
|
Votes.ElectionCycle == get_election_cycle_name(config)
|
||||||
|
)
|
||||||
|
|
||||||
|
for vote in session.scalars(stmt):
|
||||||
|
if vote.VotedForId is not None:
|
||||||
|
dm_votes[vote.VotedForId] += 1
|
||||||
|
|
||||||
|
# build the votes string
|
||||||
|
votes_str: str = "Clan Leader Votes\n===================="
|
||||||
|
votes_str += user_vote_str(cl_votes)
|
||||||
|
|
||||||
|
votes_str += "\n\nDiscord Manager Votes\n===================="
|
||||||
|
votes_str += user_vote_str(dm_votes)
|
||||||
|
|
||||||
|
return votes_str
|
||||||
|
|
||||||
|
|
||||||
|
def user_vote_str(votes: dict[int, int]) -> str:
|
||||||
|
"""
|
||||||
|
Creates the string representing how many votes each user has.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
votes (dict[int, int]): Dict of all users and how many votes they have.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The string showing names and number of votes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
for user_id, num_votes in votes.items():
|
||||||
|
return f"\n<@{user_id}>: {'☑️' * num_votes}"
|
||||||
|
|
||||||
|
|
||||||
def decorate_nomination(user_id: int, speech: str) -> str:
|
def decorate_nomination(user_id: int, speech: str) -> str:
|
||||||
"""
|
"""
|
||||||
Decorates a nomination speech so that it sits within multiple speeches better.
|
Decorates a nomination speech so that it sits within multiple speeches better.
|
||||||
|
|||||||
Reference in New Issue
Block a user