From 8394cdd6fd4db45ebab37e74944dc9d5f9c1ac17 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Sun, 17 Dec 2023 15:06:19 -0500 Subject: [PATCH] Remove nomination views once they are done. --- classes/election_cycle.py | 61 +++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/classes/election_cycle.py b/classes/election_cycle.py index 9ba4c57..3201098 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -201,16 +201,9 @@ class ElectionCycle: thread_msg: nextcord.Message = await parent.send(content=quarter_name) - # create new entry into database. thread: nextcord.Thread = await parent.create_thread( name=quarter_name, message=thread_msg ) - with Session(engine) as session: - new_cycle = ElectionInformation( - ElectionCycle=quarter_name, ThreadId=thread.id - ) - session.add(new_cycle) - session.commit() # post message announcing election # election start message is returned as an array of string because it is too long. send each string @@ -219,10 +212,22 @@ class ElectionCycle: for index, message in enumerate(messages): # if last item, add the nominate button if index + 1 == len(messages): - await thread.send(message, view=NominateView(self.config, self.guild)) + nominate_msg: nextcord.Message = await thread.send( + message, view=NominateView(self.config, self.guild) + ) else: await thread.send(message) + # create new entry into database. + with Session(engine) as session: + new_cycle = ElectionInformation( + ElectionCycle=quarter_name, + ThreadId=thread.id, + CouncilNominationMsgId=nominate_msg.id, + ) + session.add(new_cycle) + session.commit() + async def voting_start_action(self) -> None: """ Sends message informing members that voting has started. @@ -246,6 +251,12 @@ class ElectionCycle: info.CouncilVoteMsgId = vote_msg.id session.commit() + thread: nextcord.Thread = self.guild.get_thread(info.ThreadId) + nominate_msg: nextcord.Message = await thread.fetch_message( + info.CouncilNominationMsgId + ) + await nominate_msg.edit(view=None) + async def voting_end_action(self) -> None: """ Performs required actions for when voting time has ended. @@ -259,18 +270,28 @@ class ElectionCycle: self.get_election_info().ThreadId ) - # remove vote button from vote message + nominate_msg: nextcord.Message = await election_thread.send( + message, view=NominateHighCouncilView(self.config, self.guild) + ) + election_name = get_election_cycle_name(self.config) + with Session(engine) as session: - stmt = select(ElectionInformation.CouncilVoteMsgId).where( + # remove vote button from vote message + stmt = select(ElectionInformation).where( ElectionInformation.ElectionCycle == election_name ) - vote_msg_id = session.scalar(stmt) - vote_msg: nextcord.Message = await election_thread.fetch_message(vote_msg_id) - await vote_msg.edit(view=None) + info = session.scalar(stmt) + vote_msg: nextcord.Message = await election_thread.fetch_message( + info.CouncilVoteMsgId + ) + await vote_msg.edit(view=None) - # add the highcouncil role to everyone with 3 or more votes. set elected to true in database - with Session(engine) as session: + # add the highcouncil nomination message to election information + info.HighCouncilVoteMsgId = nominate_msg.id + session.commit() + + # add the highcouncil role to everyone with 3 or more votes. set elected to true in database stmt = select(Votes.VotedForId).where(Votes.ElectionCycle == election_name) vote_count = collections.Counter(session.scalars(stmt)) @@ -292,10 +313,6 @@ class ElectionCycle: reason=f"{member.display_name} has won a nomination and become a Council Elect.", ) - await election_thread.send( - message, view=NominateHighCouncilView(self.config, self.guild) - ) - async def highcouncil_election_start_action(self) -> None: """ Performs required actions for when the highcouncil is elected. @@ -320,6 +337,12 @@ class ElectionCycle: info.HighCouncilVoteMsgId = vote_msg.id session.commit() + # remove highcouncil nomination view + nomination_msg: nextcord.Message = await election_thread.fetch_message( + info.HighCouncilNominationMsgId + ) + await nomination_msg.edit(view=None) + async def term_start_action(self) -> None: """ Marks the election as over.