From 9867f91268520613255672204d1dc2ed1e2b6efa Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 25 Jul 2023 14:41:16 -0400 Subject: [PATCH 1/4] Add the highcouncil vote start message. --- bot_messages/highcouncil_election.txt | 2 +- bot_messages/highcouncil_vote.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 bot_messages/highcouncil_vote.txt diff --git a/bot_messages/highcouncil_election.txt b/bot_messages/highcouncil_election.txt index 50f5422..b6fdeb9 100644 --- a/bot_messages/highcouncil_election.txt +++ b/bot_messages/highcouncil_election.txt @@ -10,4 +10,4 @@ From {highcouncil_election_announce} to {highcouncil_election_start}, you will b Each member of the CCE can cast one for each category by using the emotes: <:Rank_Owner:479008325137072155> for Clan Leader and <:Rank_Deputy:479008295319896064> for Discord Server Manager. If needed, the icon 🤷 can be used to abstain to vote in any or both categories and it should be apply to all candidates of that category. -Votes can be cast until the {highcouncil_election_end}, so we can announce and have everyone set up to start the term by {term_start} \ No newline at end of file +Votes can be cast until the {highcouncil_election_end}, so we can announce and have everyone set up to start the term by {term_start}. \ No newline at end of file diff --git a/bot_messages/highcouncil_vote.txt b/bot_messages/highcouncil_vote.txt new file mode 100644 index 0000000..b561dac --- /dev/null +++ b/bot_messages/highcouncil_vote.txt @@ -0,0 +1 @@ +<@&{clan_council_elect_role_id}> it is now time to vote for the high council! You have until {term_start} to complete the vote. \ No newline at end of file From d67940aa2632a4a997be198b6b89d3f279e105c3 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 25 Jul 2023 14:50:44 -0400 Subject: [PATCH 2/4] Create new function for getting election information. --- classes/election_cycle.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/classes/election_cycle.py b/classes/election_cycle.py index b45f44d..057425f 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -206,3 +206,17 @@ class ElectionCycle: """ return f"{self.election_start.year} {self.elecion_cycle.name} election" + + def get_election_info(self) -> ElectionInformation: + """ + Gets information for current election. + + Returns: + ElectionInformation: The information from the database about the current election. + """ + + with Session(engine) as session: + stmt = select(ElectionInformation).where( + ElectionInformation.ElectionCycle == self.get_election_cycle_name() + ) + return session.scalar(stmt) From 1b4c5780dfa8e9186b1cfbaec96c453c2ddb57a6 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 25 Jul 2023 14:51:17 -0400 Subject: [PATCH 3/4] Refactor other function to use get_election_info. --- classes/election_cycle.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/classes/election_cycle.py b/classes/election_cycle.py index 057425f..671b47d 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -159,14 +159,9 @@ class ElectionCycle: """ message = self.build_vote_start() clan_member_role: nextcord.Role = self.guild.get_role(self.config.params.clan_member_role_id) - with Session(engine) as session: - stmt = select(ElectionInformation).where( - ElectionInformation.ElectionCycle == self.get_election_cycle_name() - ) - election_info = session.scalar(stmt) - election_channel = self.guild.get_channel(election_info.ElectionChannel) - await election_channel.send(message) - await election_channel.set_permissions(clan_member_role, send_messages=False) + election_channel = self.guild.get_channel(self.get_election_info().ElectionChannel) + await election_channel.send(message) + await election_channel.set_permissions(clan_member_role, send_messages=False) async def voting_end_action(self) -> None: """ @@ -174,14 +169,9 @@ class ElectionCycle: """ message = self.build_highcouncil_election_announce() council_elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id) - with Session(engine) as session: - stmt = select(ElectionInformation).where( - ElectionInformation.ElectionCycle == self.get_election_cycle_name() - ) - election_info = session.scalar(stmt) - election_channel = self.guild.get_channel(election_info.ElectionChannel) - await election_channel.send(message) - await election_channel.set_permissions(council_elect_role, send_messages=True) + election_channel = self.guild.get_channel(self.get_election_info().ElectionChannel) + await election_channel.send(message) + await election_channel.set_permissions(council_elect_role, send_messages=True) async def highcouncil_election_action(self) -> None: """ From 1731bd46a60b55b295413e61635eeab8d73a4635 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 25 Jul 2023 14:52:48 -0400 Subject: [PATCH 4/4] Fill out highcouncil_election_start_action --- classes/election_cycle.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/classes/election_cycle.py b/classes/election_cycle.py index 671b47d..2f5a888 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -90,6 +90,22 @@ class ElectionCycle: term_start_date=self.term_start.strftime("%B %d"), ) + def build_highcouncil_vote_start(self) -> str: + """ + Builds the message to announce that highcouncil voting has started. + + Returns: + str: Message to send. + """ + + with open("bot_messages/highcouncil_vote.txt", mode="r", encoding="utf8") as file: + message = file.read() + + return message.format( + clan_council_elect_role_id=self.config.params.clan_council_elect_role_id, + term_start_date=self.term_start.strftime("%B %d"), + ) + def build_vote_start(self) -> str: """ Builds the voting start message out of template and configurations. @@ -123,7 +139,7 @@ class ElectionCycle: elif today.date() == self.voting_end.date(): await self.voting_end_action() elif today.date() == self.highcouncil_election_start.date(): - await self.highcouncil_election_action() + await self.highcouncil_election_start_action() elif today.date() == self.term_start.date(): await self.term_start_action() elif today.date() == self.term_end.date(): @@ -173,11 +189,14 @@ class ElectionCycle: await election_channel.send(message) await election_channel.set_permissions(council_elect_role, send_messages=True) - async def highcouncil_election_action(self) -> None: + async def highcouncil_election_start_action(self) -> None: """ Performs required actions for when the highcouncil is elected. """ - print("Highcouncil election has started.") + + message = self.build_highcouncil_vote_start() + election_channel = self.guild.get_channel(self.get_election_info().ElectionChannel) + await election_channel.send(message) async def term_start_action(self) -> None: msg: str = "the term has started"