Remove config param from get_current_election_cycle(). Update test.py to use new settings.
This commit is contained in:
+15
-27
@@ -1,17 +1,12 @@
|
|||||||
"""Commands for testing."""
|
"""Commands for testing."""
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import application_checks, commands
|
from nextcord.ext import application_checks, commands
|
||||||
|
|
||||||
from classes.election import Election
|
from classes.election import Election
|
||||||
|
from DakinySettings import settings
|
||||||
from utils import GUILDS, get_current_election_cycle
|
from utils import GUILDS, get_current_election_cycle
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from DakinySettings import DakinySettings
|
|
||||||
|
|
||||||
|
|
||||||
ME = 206602713511886849
|
ME = 206602713511886849
|
||||||
|
|
||||||
|
|
||||||
@@ -44,10 +39,9 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinySettings = self.bot.config
|
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(),
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_start_action()
|
await cycle.election_start_action()
|
||||||
await interaction.send("Test command sent.", ephemeral=True)
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
@@ -61,10 +55,9 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinySettings = self.bot.config
|
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(),
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_start_action()
|
await cycle.voting_start_action()
|
||||||
await interaction.send("Test command sent.", ephemeral=True)
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
@@ -78,10 +71,9 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinySettings = self.bot.config
|
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(),
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_end_action()
|
await cycle.voting_end_action()
|
||||||
await interaction.send("Test command sent.", ephemeral=True)
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
@@ -95,10 +87,9 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinySettings = self.bot.config
|
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(),
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.highcouncil_election_start_action()
|
await cycle.highcouncil_election_start_action()
|
||||||
await interaction.send("Test command sent.", ephemeral=True)
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
@@ -112,10 +103,9 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinySettings = self.bot.config
|
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(),
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_reminder()
|
await cycle.election_reminder()
|
||||||
await interaction.send("Test command sent.", ephemeral=True)
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
@@ -129,10 +119,9 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinySettings = self.bot.config
|
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(),
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.check_date()
|
await cycle.check_date()
|
||||||
await interaction.send("Test command sent.", ephemeral=True)
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
@@ -146,10 +135,9 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinySettings = self.bot.config
|
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(),
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.term_start_action()
|
await cycle.term_start_action()
|
||||||
await interaction.send("Test command sent.", ephemeral=True)
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
Returns:
|
Returns:
|
||||||
Election: Current election cycle, None if there is no election happening.
|
Election: Current election cycle, None if there is no election happening.
|
||||||
"""
|
"""
|
||||||
cycle = get_current_election_cycle(settings)
|
cycle = get_current_election_cycle()
|
||||||
|
|
||||||
# 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:
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ def get_election_name() -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: the name of the election cycle
|
str: the name of the election cycle
|
||||||
"""
|
"""
|
||||||
cycle = get_current_election_cycle(settings)
|
cycle = get_current_election_cycle()
|
||||||
current_cycle = settings.election_cycles[cycle]
|
current_cycle = settings.election_cycles[cycle]
|
||||||
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ def get_quarter_name() -> str:
|
|||||||
return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
||||||
|
|
||||||
|
|
||||||
def get_current_election_cycle(config: DakinySettings) -> int:
|
def get_current_election_cycle() -> 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.
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ def get_current_election_cycle(config: DakinySettings) -> int:
|
|||||||
"""
|
"""
|
||||||
today = datetime.now(tz=UTC)
|
today = datetime.now(tz=UTC)
|
||||||
|
|
||||||
for cycle, election in enumerate(config.election_cycles):
|
for cycle, election in enumerate(settings.election_cycles):
|
||||||
if (
|
if (
|
||||||
today.date() >= get_datetime(election.election_start).date()
|
today.date() >= get_datetime(election.election_start).date()
|
||||||
and today.date() <= get_datetime(election.term_start).date()
|
and today.date() <= get_datetime(election.term_start).date()
|
||||||
@@ -105,7 +105,7 @@ def get_current_election_cycle(config: DakinySettings) -> int:
|
|||||||
return cycle
|
return cycle
|
||||||
|
|
||||||
# It isn't a current election, get the quarter
|
# It isn't a current election, get the quarter
|
||||||
return get_quarter_cycle(config)
|
return get_quarter_cycle(settings)
|
||||||
|
|
||||||
|
|
||||||
def get_quarter_cycle(config: DakinySettings) -> int:
|
def get_quarter_cycle(config: DakinySettings) -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user