From 8d2f2f7dbaff3ac0f6d7cc0383eae7680a0642ea Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 7 Nov 2023 15:36:33 -0500 Subject: [PATCH] Thread create ini election start. Modified config and database to use threads. --- classes/election_cycle.py | 14 ++++++++++---- config.py | 1 + database_setup/database.sql | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/classes/election_cycle.py b/classes/election_cycle.py index fff8fd5..9729978 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -185,15 +185,21 @@ class ElectionCycle: Performs required actions for when the election cycle starts. """ # create new channel for election - category: nextcord.CategoryChannel = self.guild.get_channel(self.config.params.active_category_id) + parent: nextcord.TextChannel = self.guild.get_channel( + self.config.params.voting_parent_id + ) quarter_name: str = get_election_cycle_name(self.config) # create new entry into database. + thread: nextcord.Thread = await parent.create_thread(quarter_name) clan_member_role: nextcord.Role = self.guild.get_role( self.config.params.clan_member_role_id ) + await thread.set_permissions(clan_member_role, add_reactions=True) with Session(engine) as session: - new_cycle = ElectionInformation(ElectionCycle=quarter_name, ElectionChannel=election_channel.id) + new_cycle = ElectionInformation( + ElectionCycle=quarter_name, ThreadId=thread.id + ) session.add(new_cycle) session.commit() @@ -204,9 +210,9 @@ class ElectionCycle: for index, message in enumerate(messages): # if last item, add the nominate button if index + 1 == len(messages): - await election_channel.send(message, view=NominateView(self.config)) + await thread.send(message, view=NominateView(self.config)) else: - await election_channel.send(message) + await thread.send(message) async def voting_start_action(self) -> None: """ diff --git a/config.py b/config.py index 1dfc500..f7f10b1 100644 --- a/config.py +++ b/config.py @@ -22,6 +22,7 @@ class Params: general_channel_id: int guild_id: int high_council_role_id: int + voting_parent_id: int @dataclass diff --git a/database_setup/database.sql b/database_setup/database.sql index 299e621..64f77a9 100644 --- a/database_setup/database.sql +++ b/database_setup/database.sql @@ -1,6 +1,6 @@ CREATE TABLE ElectionInformation( ElectionCycle varchar(30) not null unique, - ElectionChannel bigint unsigned not null, + ThreadId bigint unsigned not null, CouncilVoteMsgId bigint unsigned, PRIMARY KEY (ElectionCycle) );