diff --git a/DakinySettings.py b/DakinySettings.py index aee5abc..5939729 100644 --- a/DakinySettings.py +++ b/DakinySettings.py @@ -23,6 +23,7 @@ class ChannelIds: class Election: """Class defines relevant election dates.""" + active: bool election_start: str highcouncil_election_announce: str highcouncil_election_end: str diff --git a/classes/election.py b/classes/election.py index f62f89a..5f02483 100644 --- a/classes/election.py +++ b/classes/election.py @@ -49,6 +49,7 @@ class Election: """ self.cycle = cycle self.election_cycle = settings.election_cycles[self.cycle] + self.active = self.election_cycle.active self.election_start: datetime = get_datetime(self.election_cycle.election_start) self.term_start: datetime = get_datetime(self.election_cycle.term_start) self.term_end: datetime = get_datetime(self.election_cycle.term_end) diff --git a/cogs/commands/test.py b/cogs/commands/test.py index 789d1d4..a53fa9e 100644 --- a/cogs/commands/test.py +++ b/cogs/commands/test.py @@ -5,7 +5,7 @@ from nextcord.ext import application_checks, commands from classes.election import Election from DakinySettings import settings -from utils import GUILDS, get_current_election_cycle +from utils import GUILDS, get_active_election_cycle ME = 206602713511886849 @@ -40,7 +40,7 @@ class TestCog(commands.Cog, name="Test commands."): interaction (nextcord.Interaction): Interaction with the message. """ cycle = Election( - get_current_election_cycle(), + get_active_election_cycle(), self.bot.get_guild(settings.params.guild_id), ) await cycle.election_start_action() @@ -56,7 +56,7 @@ class TestCog(commands.Cog, name="Test commands."): interaction (nextcord.Interaction): Interaction with the message. """ cycle = Election( - get_current_election_cycle(), + get_active_election_cycle(), self.bot.get_guild(settings.params.guild_id), ) await cycle.voting_start_action() @@ -72,7 +72,7 @@ class TestCog(commands.Cog, name="Test commands."): interaction (nextcord.Interaction): Interaction with the message. """ cycle = Election( - get_current_election_cycle(), + get_active_election_cycle(), self.bot.get_guild(settings.params.guild_id), ) await cycle.voting_end_action() @@ -88,7 +88,7 @@ class TestCog(commands.Cog, name="Test commands."): interaction (nextcord.Interaction): Interaction with the message. """ cycle = Election( - get_current_election_cycle(), + get_active_election_cycle(), self.bot.get_guild(settings.params.guild_id), ) await cycle.highcouncil_election_start_action() @@ -104,7 +104,7 @@ class TestCog(commands.Cog, name="Test commands."): interaction (nextcord.Interaction): Interaction with the message. """ cycle = Election( - get_current_election_cycle(), + get_active_election_cycle(), self.bot.get_guild(settings.params.guild_id), ) await cycle.election_reminder() @@ -120,7 +120,7 @@ class TestCog(commands.Cog, name="Test commands."): interaction (nextcord.Interaction): Interaction with the message. """ cycle = Election( - get_current_election_cycle(), + get_active_election_cycle(), self.bot.get_guild(settings.params.guild_id), ) await cycle.check_date() @@ -136,7 +136,7 @@ class TestCog(commands.Cog, name="Test commands."): interaction (nextcord.Interaction): Interaction with the message. """ cycle = Election( - get_current_election_cycle(), + get_active_election_cycle(), self.bot.get_guild(settings.params.guild_id), ) await cycle.term_start_action() diff --git a/cogs/loops/daily_loop.py b/cogs/loops/daily_loop.py index ac9daf5..b359da8 100644 --- a/cogs/loops/daily_loop.py +++ b/cogs/loops/daily_loop.py @@ -2,6 +2,7 @@ import random from datetime import UTC, datetime, time +from tkinter import NO from typing import TYPE_CHECKING from nextcord.ext import commands, tasks @@ -13,7 +14,7 @@ from classes.election import Election from DakinySettings import settings from database_setup.sql_data_classes import UserBirthday, engine from main import birthday_list -from utils import get_current_election_cycle +from utils import get_active_election_cycle if TYPE_CHECKING: import nextcord @@ -75,13 +76,15 @@ class DailyLoop(commands.Cog, name="Daily Loop"): Returns: Election: Current election cycle, None if there is no election happening. """ - cycle = get_current_election_cycle() + cycle = get_active_election_cycle() # prevent exception from using cycle as an Int in an array if cycle is None: return None - return Election(cycle, self.bot.get_guild(settings.params.guild_id)) + election = Election(cycle, self.bot.get_guild(settings.params.guild_id)) + + return election if election.active else None def update_birthdays(self) -> None: """Goes through database to collect all birthdays that are today. Adds user's id to birthday list.""" diff --git a/utils.py b/utils.py index 2531bd0..e63846b 100644 --- a/utils.py +++ b/utils.py @@ -64,7 +64,7 @@ def get_election_name() -> str: Returns: str: the name of the election cycle """ - cycle = get_current_election_cycle() + cycle = get_active_election_cycle() current_cycle = settings.election_cycles[cycle] return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" @@ -82,7 +82,7 @@ def get_quarter_name() -> str: return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" -def get_current_election_cycle() -> int: +def get_active_election_cycle() -> int: """ Returns index for active election. An election is considered active between the election start and the term start. @@ -104,7 +104,9 @@ def get_current_election_cycle() -> int: def get_quarter_cycle() -> int: """ - Returns the index for the current cycle/quarter. Defined as between term start and end. Shouldn't return none. + Returns the index for the current cycle/quarter. Defined as between term start and end. + + Can return None if entire year isn't covered by cycles. Returns: int: cycle index for current cycle.