move functions to get election cycle index and name into utils.
build_develop / build (push) Successful in 1m52s
build_develop / build (push) Successful in 1m52s
This commit is contained in:
@@ -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_datetime
|
||||
from utils import get_current_cycle
|
||||
|
||||
|
||||
class DailyLoop(commands.Cog, name="Daily Loop"):
|
||||
@@ -40,7 +40,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
||||
"""
|
||||
|
||||
if self.current_election is None:
|
||||
self.current_election = self.get_current_cycle()
|
||||
self.current_election = self.get_election_cycle()
|
||||
|
||||
if self.current_election is not None:
|
||||
await self.current_election.check_date()
|
||||
@@ -65,9 +65,9 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
||||
await self.bot.wait_until_ready()
|
||||
|
||||
# Bot needs to know guilds to get the current cycle.
|
||||
self.current_election = self.get_current_cycle()
|
||||
self.current_election = self.get_election_cycle()
|
||||
|
||||
def get_current_cycle(self) -> ElectionCycle:
|
||||
def get_election_cycle(self) -> ElectionCycle:
|
||||
"""
|
||||
Creates an object for the current election cycle if one is active. An election is considered active
|
||||
between the election start and the term start.
|
||||
@@ -76,18 +76,10 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
||||
ElectionCycle: Current election cycle, None if there is no election happening.
|
||||
"""
|
||||
|
||||
today = datetime.today()
|
||||
config: DakinyConfig = self.bot.config
|
||||
current_election = None
|
||||
cycle = get_current_cycle(config)
|
||||
|
||||
for cycle, election in enumerate(config.election_cycles):
|
||||
if (
|
||||
today.date() >= get_datetime(election.election_start).date()
|
||||
and today.date() <= get_datetime(election.term_start).date()
|
||||
):
|
||||
current_election = ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
|
||||
|
||||
return current_election
|
||||
return ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
|
||||
|
||||
def update_birthdays(self) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user