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
+41 -4
View File
@@ -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.