diff --git a/cogs/commands/test.py b/cogs/commands/test.py index 42c8148..d1a4a8b 100644 --- a/cogs/commands/test.py +++ b/cogs/commands/test.py @@ -7,7 +7,7 @@ from nextcord.ext import application_checks, commands from classes.election_cycle import ElectionCycle from config import DakinyConfig -from utils import get_current_cycle +from utils import get_current_election_cycle def is_me(): @@ -50,7 +50,7 @@ class TestCog(commands.Cog, name="Test commands."): config: DakinyConfig = self.bot.config cycle = ElectionCycle( - get_current_cycle(config), + get_current_election_cycle(config), config, self.bot.get_guild(config.params.guild_id), ) @@ -67,7 +67,7 @@ class TestCog(commands.Cog, name="Test commands."): """ config: DakinyConfig = self.bot.config cycle = ElectionCycle( - get_current_cycle(config), + get_current_election_cycle(config), config, self.bot.get_guild(config.params.guild_id), ) @@ -84,7 +84,7 @@ class TestCog(commands.Cog, name="Test commands."): """ config: DakinyConfig = self.bot.config cycle = ElectionCycle( - get_current_cycle(config), + get_current_election_cycle(config), config, self.bot.get_guild(config.params.guild_id), ) @@ -101,7 +101,7 @@ class TestCog(commands.Cog, name="Test commands."): """ config: DakinyConfig = self.bot.config cycle = ElectionCycle( - get_current_cycle(config), + get_current_election_cycle(config), config, self.bot.get_guild(config.params.guild_id), ) @@ -112,7 +112,7 @@ class TestCog(commands.Cog, name="Test commands."): async def election_reminder(self, interaction: nextcord.Interaction): config: DakinyConfig = self.bot.config cycle = ElectionCycle( - get_current_cycle(config), + get_current_election_cycle(config), config, self.bot.get_guild(config.params.guild_id), ) @@ -123,7 +123,7 @@ class TestCog(commands.Cog, name="Test commands."): async def daily(self, interaction: nextcord.Interaction): config: DakinyConfig = self.bot.config cycle = ElectionCycle( - get_current_cycle(config), + get_current_election_cycle(config), config, self.bot.get_guild(config.params.guild_id), ) @@ -134,7 +134,7 @@ class TestCog(commands.Cog, name="Test commands."): async def term_start(self, interaction: nextcord.Interaction): config: DakinyConfig = self.bot.config cycle = ElectionCycle( - get_current_cycle(config), + get_current_election_cycle(config), config, self.bot.get_guild(config.params.guild_id), ) diff --git a/cogs/loops/daily_loop.py b/cogs/loops/daily_loop.py index 3f33795..a483454 100644 --- a/cogs/loops/daily_loop.py +++ b/cogs/loops/daily_loop.py @@ -15,7 +15,7 @@ from classes.election_cycle import ElectionCycle from config import DakinyConfig from dakiny_bot import birthday_list from database_setup.sql_data_classes import UserBirthday, engine -from utils import get_current_cycle +from utils import get_current_election_cycle class DailyLoop(commands.Cog, name="Daily Loop"): @@ -77,7 +77,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"): """ config: DakinyConfig = self.bot.config - cycle = get_current_cycle(config) + cycle = get_current_election_cycle(config) # prevent exception from using cycle as an Int in an array if cycle is None: diff --git a/utils.py b/utils.py index cb1454a..657f2cd 100644 --- a/utils.py +++ b/utils.py @@ -48,12 +48,27 @@ def get_election_cycle_name(config: DakinyConfig) -> str: Returns: str: the name of the election cycle """ + cycle = get_current_election_cycle(config) + current_cycle = config.election_cycles[cycle] + + return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" + + +def get_cycle_name(config: DakinyConfig) -> str: + """ + Builds the name of the current cycle/quarter + + Args: + config (DakinyConfig): the config used to know the election cycle. + + Returns: + str: the name of the cycle. + """ + cycle = get_current_cycle(config) current_cycle = config.election_cycles[cycle] - return ( - f"vote-{get_datetime(current_cycle.election_start).year}-{current_cycle.name}" - ) + return f"{get_datetime(current_cycle.term_start.year)}-{current_cycle.name}" def get_dm_election_name(config: DakinyConfig) -> str: @@ -84,7 +99,7 @@ def get_cl_election_name(config: DakinyConfig) -> str: return f"{get_election_cycle_name(config)}-cl" -def get_current_cycle(config: DakinyConfig) -> int: +def get_current_election_cycle(config: DakinyConfig) -> int: """ Returns index for active election. An election is considered active between the election start and the term start. @@ -107,6 +122,28 @@ def get_current_cycle(config: DakinyConfig) -> int: return None +def get_current_cycle(config: DakinyConfig) -> int: + """ + Returns the index for the current cycle/quarter. Defined as between term start and end. Shouldn't return none + + Args: + config (DakinyConfig): Config object to use + + Returns: + int: cycle index for current cycle. + """ + + today = datetime.today() + for cycle, election in enumerate(config.election_cycles): + if ( + today.date() >= get_datetime(election.term_start).date() + and today.date() <= get_datetime(election.term_end).date() + ): + return cycle + + return None + + def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str: """ Creates a string that contains all nominees and their votes to be sent as a discord message.