Add active parameter to elections. Only return an election for use if the election is active.

This commit is contained in:
2024-09-07 15:46:30 -04:00
parent 70676a98dd
commit 3c31d0ad33
5 changed files with 21 additions and 14 deletions
+8 -8
View File
@@ -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()
+6 -3
View File
@@ -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."""