From d149caafeada097961b8f56bff7effaea10e7388 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Fri, 3 Nov 2023 17:31:52 -0400 Subject: [PATCH] Add election reminder. Happens daily starting 3 days before election end. --- classes/election_cycle.py | 16 +++++++++++++++- cogs/commands/test.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/classes/election_cycle.py b/classes/election_cycle.py index a7c02ac..3638217 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -3,7 +3,7 @@ Contains the election cycle class """ import collections -from datetime import datetime +from datetime import datetime, timedelta import nextcord from sqlalchemy import select @@ -140,6 +140,8 @@ class ElectionCycle: await self.election_start_action() elif today.date() == self.voting_start.date(): await self.voting_start_action() + elif (self.voting_end - timedelta(3)).date() <= today.date() < self.voting_end.date(): + await self.election_reminder() elif today.date() == self.voting_end.date(): await self.voting_end_action() elif today.date() == self.highcouncil_election_start.date(): @@ -273,3 +275,15 @@ class ElectionCycle: ElectionInformation.ElectionCycle == get_election_cycle_name(self.config) ) return session.scalar(stmt) + + async def election_reminder(self) -> None: + """ + Sends a message to general chat reminder clan about election. + """ + + general: nextcord.TextChannel = self.guild.get_channel(self.config.params.general_channel_id) + + message = f"Reminder to <@&{self.config.params.clan_member_role_id}>! Clan elections are happening! Head over " + message += f"to <#{self.get_election_info().ElectionChannel}> to cast your vote!" + + await general.send(content=message) diff --git a/cogs/commands/test.py b/cogs/commands/test.py index 6b3a863..1838b08 100644 --- a/cogs/commands/test.py +++ b/cogs/commands/test.py @@ -87,3 +87,15 @@ class TestCog(commands.Cog, name="Test commands."): config: DakinyConfig = self.bot.config cycle = ElectionCycle(get_current_cycle(config), config, self.bot.get_guild(config.params.guild_id)) await cycle.voting_end_action() + + @test.subcommand() + async def election_reminder(self, interaction: nextcord.Interaction): + config: DakinyConfig = self.bot.config + cycle = ElectionCycle(get_current_cycle(config), config, self.bot.get_guild(config.params.guild_id)) + await cycle.election_reminder() + + @test.subcommand() + async def daily(self, interaction: nextcord.Interaction): + config: DakinyConfig = self.bot.config + cycle = ElectionCycle(get_current_cycle(config), config, self.bot.get_guild(config.params.guild_id)) + await cycle.check_date()