diff --git a/classes/election_cycle.py b/classes/election_cycle.py index 854a86a..36514dd 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -6,6 +6,7 @@ from datetime import datetime, timedelta import nextcord from nextcord.ext import commands +from sqlalchemy import select from sqlalchemy.orm import Session from config import DakinyConfig @@ -19,7 +20,7 @@ class ElectionCycle: the cycle. """ - def __init__(self, cycle: int, bot) -> None: + def __init__(self, cycle: int, bot: commands.Bot) -> None: """ Generates all dates relevant to the election cycle from input election start, term start and end dates. @@ -40,7 +41,7 @@ class ElectionCycle: self.highcouncil_election_announce: datetime = self.voting_end + timedelta(days=1) self.highcouncil_election_start: datetime = self.highcouncil_election_announce + timedelta(days=3) self.highcouncil_election_end: datetime = self.term_start - timedelta(days=1) - self.bot: commands.Bot = bot + self.guild: nextcord.Guild = bot.get_guild(self.config.params.guild_id) def build_election_announcement(self) -> list[str]: """ @@ -127,7 +128,7 @@ class ElectionCycle: Performs required actions for when the election cycle starts. """ # create new channel for election - category: nextcord.CategoryChannel = self.bot.get_channel(self.config.params.active_category_id) + category: nextcord.CategoryChannel = self.guild.get_channel(self.config.params.active_category_id) quarter_name: str = self.get_election_cycle_name() # create new entry into database. @@ -146,41 +147,40 @@ class ElectionCycle: async def voting_start_action(self) -> None: """ - Performs required actions for when voting for candidates starts. + Sends message informing members that voting has started. + Removes write permission from the general clan member role. + Adds the voting emote to all messages not sent by the vote. (This is temporary until voting is managed.) """ - print("Voting has started") - await self.message_me("Voting has started") + 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) async def voting_end_action(self) -> None: """ Performs required actions for when voting time has ended. """ print("voting has ended") - await self.message_me("voting has ended") async def highcouncil_election_action(self) -> None: """ Performs required actions for when the highcouncil is elected. """ print("Highcouncil election has started.") - await self.message_me("Highcouncil election has started.") async def term_start_action(self) -> None: msg: str = "the term has started" print(msg) - self.message_me(msg) async def term_end_action(self): msg: str = "the term has ended" print(msg) - self.message_me(msg) - - async def message_me(self, msg: str): - """ - message a string to me - """ - imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849) - await imcompiling.send(msg) def get_election_cycle_name(self) -> str: """ diff --git a/cogs/commands/test.py b/cogs/commands/test.py index 95bcbbc..948a331 100644 --- a/cogs/commands/test.py +++ b/cogs/commands/test.py @@ -53,3 +53,14 @@ class TestCog(commands.Cog, name="Test commands."): cycle = ElectionCycle(0, self.bot) await cycle.election_start_action() + + @test.subcommand() + async def voting_start(self, interaction: nextcord.Interaction): + """ + tests the voting start action + + Args: + interaction (nextcord.Interaction): _description_ + """ + cycle = ElectionCycle(0, self.bot) + await cycle.voting_start_action() diff --git a/config.py b/config.py index 80c86f0..979ac75 100644 --- a/config.py +++ b/config.py @@ -18,6 +18,7 @@ class Params: clan_info_channel_id: int clan_member_role_id: int discord_token: str + guild_id: int high_council_role_id: int voting_emote_id: str diff --git a/permissions_required.txt b/permissions_required.txt index dc1e30b..bc1e455 100644 --- a/permissions_required.txt +++ b/permissions_required.txt @@ -1,3 +1,4 @@ Discord permissions required for bot to operate: -manage channels \ No newline at end of file +manage channels +manage roles \ No newline at end of file