change get election cycle name, add new function to get the current cycle for quarter name usage.

This commit is contained in:
2024-05-08 16:20:46 -04:00
parent e1787f68d5
commit a963171b16
3 changed files with 51 additions and 14 deletions
+8 -8
View File
@@ -7,7 +7,7 @@ from nextcord.ext import application_checks, commands
from classes.election_cycle import ElectionCycle from classes.election_cycle import ElectionCycle
from config import DakinyConfig from config import DakinyConfig
from utils import get_current_cycle from utils import get_current_election_cycle
def is_me(): def is_me():
@@ -50,7 +50,7 @@ class TestCog(commands.Cog, name="Test commands."):
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = ElectionCycle( cycle = ElectionCycle(
get_current_cycle(config), get_current_election_cycle(config),
config, config,
self.bot.get_guild(config.params.guild_id), self.bot.get_guild(config.params.guild_id),
) )
@@ -67,7 +67,7 @@ class TestCog(commands.Cog, name="Test commands."):
""" """
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = ElectionCycle( cycle = ElectionCycle(
get_current_cycle(config), get_current_election_cycle(config),
config, config,
self.bot.get_guild(config.params.guild_id), self.bot.get_guild(config.params.guild_id),
) )
@@ -84,7 +84,7 @@ class TestCog(commands.Cog, name="Test commands."):
""" """
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = ElectionCycle( cycle = ElectionCycle(
get_current_cycle(config), get_current_election_cycle(config),
config, config,
self.bot.get_guild(config.params.guild_id), self.bot.get_guild(config.params.guild_id),
) )
@@ -101,7 +101,7 @@ class TestCog(commands.Cog, name="Test commands."):
""" """
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = ElectionCycle( cycle = ElectionCycle(
get_current_cycle(config), get_current_election_cycle(config),
config, config,
self.bot.get_guild(config.params.guild_id), 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): async def election_reminder(self, interaction: nextcord.Interaction):
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = ElectionCycle( cycle = ElectionCycle(
get_current_cycle(config), get_current_election_cycle(config),
config, config,
self.bot.get_guild(config.params.guild_id), 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): async def daily(self, interaction: nextcord.Interaction):
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = ElectionCycle( cycle = ElectionCycle(
get_current_cycle(config), get_current_election_cycle(config),
config, config,
self.bot.get_guild(config.params.guild_id), 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): async def term_start(self, interaction: nextcord.Interaction):
config: DakinyConfig = self.bot.config config: DakinyConfig = self.bot.config
cycle = ElectionCycle( cycle = ElectionCycle(
get_current_cycle(config), get_current_election_cycle(config),
config, config,
self.bot.get_guild(config.params.guild_id), self.bot.get_guild(config.params.guild_id),
) )
+2 -2
View File
@@ -15,7 +15,7 @@ from classes.election_cycle import ElectionCycle
from config import DakinyConfig from config import DakinyConfig
from dakiny_bot import birthday_list from dakiny_bot import birthday_list
from database_setup.sql_data_classes import UserBirthday, engine 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"): class DailyLoop(commands.Cog, name="Daily Loop"):
@@ -77,7 +77,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
""" """
config: DakinyConfig = self.bot.config 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 # prevent exception from using cycle as an Int in an array
if cycle is None: if cycle is None:
+41 -4
View File
@@ -48,12 +48,27 @@ def get_election_cycle_name(config: DakinyConfig) -> str:
Returns: Returns:
str: the name of the election cycle 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) cycle = get_current_cycle(config)
current_cycle = config.election_cycles[cycle] current_cycle = config.election_cycles[cycle]
return ( return f"{get_datetime(current_cycle.term_start.year)}-{current_cycle.name}"
f"vote-{get_datetime(current_cycle.election_start).year}-{current_cycle.name}"
)
def get_dm_election_name(config: DakinyConfig) -> str: 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" 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. 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 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: 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. Creates a string that contains all nominees and their votes to be sent as a discord message.