Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1305e15edf | ||
|
|
86e9e3e32b | ||
|
|
d7a0480c2b | ||
|
|
8457c09b5b | ||
|
|
3c31d0ad33 |
@@ -23,6 +23,7 @@ class ChannelIds:
|
|||||||
class Election:
|
class Election:
|
||||||
"""Class defines relevant election dates."""
|
"""Class defines relevant election dates."""
|
||||||
|
|
||||||
|
active: bool
|
||||||
election_start: str
|
election_start: str
|
||||||
highcouncil_election_announce: str
|
highcouncil_election_announce: str
|
||||||
highcouncil_election_end: str
|
highcouncil_election_end: str
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class Election:
|
|||||||
"""
|
"""
|
||||||
self.cycle = cycle
|
self.cycle = cycle
|
||||||
self.election_cycle = settings.election_cycles[self.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.election_start: datetime = get_datetime(self.election_cycle.election_start)
|
||||||
self.term_start: datetime = get_datetime(self.election_cycle.term_start)
|
self.term_start: datetime = get_datetime(self.election_cycle.term_start)
|
||||||
self.term_end: datetime = get_datetime(self.election_cycle.term_end)
|
self.term_end: datetime = get_datetime(self.election_cycle.term_end)
|
||||||
|
|||||||
+20
-8
@@ -5,7 +5,7 @@ from nextcord.ext import application_checks, commands
|
|||||||
|
|
||||||
from classes.election import Election
|
from classes.election import Election
|
||||||
from DakinySettings import settings
|
from DakinySettings import settings
|
||||||
from utils import GUILDS, get_current_election_cycle
|
from utils import GUILDS, get_active_election_cycle, get_quarter_name
|
||||||
|
|
||||||
ME = 206602713511886849
|
ME = 206602713511886849
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_start_action()
|
await cycle.election_start_action()
|
||||||
@@ -56,7 +56,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_start_action()
|
await cycle.voting_start_action()
|
||||||
@@ -72,7 +72,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_end_action()
|
await cycle.voting_end_action()
|
||||||
@@ -88,7 +88,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.highcouncil_election_start_action()
|
await cycle.highcouncil_election_start_action()
|
||||||
@@ -104,7 +104,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_reminder()
|
await cycle.election_reminder()
|
||||||
@@ -120,7 +120,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.check_date()
|
await cycle.check_date()
|
||||||
@@ -136,8 +136,20 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.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)
|
||||||
|
|
||||||
|
@test.subcommand()
|
||||||
|
@is_me()
|
||||||
|
async def get_quarter_name(self, interaction: nextcord.Interaction) -> None:
|
||||||
|
"""
|
||||||
|
Tests getting the quarter name.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
|
"""
|
||||||
|
name = get_quarter_name()
|
||||||
|
await interaction.send(name)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from classes.election import Election
|
|||||||
from DakinySettings import settings
|
from DakinySettings import settings
|
||||||
from database_setup.sql_data_classes import UserBirthday, engine
|
from database_setup.sql_data_classes import UserBirthday, engine
|
||||||
from main import birthday_list
|
from main import birthday_list
|
||||||
from utils import get_current_election_cycle
|
from utils import get_active_election_cycle
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import nextcord
|
import nextcord
|
||||||
@@ -75,13 +75,15 @@ 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()
|
cycle = get_active_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:
|
||||||
return 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:
|
def update_birthdays(self) -> None:
|
||||||
"""Goes through database to collect all birthdays that are today. Adds user's id to birthday list."""
|
"""Goes through database to collect all birthdays that are today. Adds user's id to birthday list."""
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ def get_datetime(day: str) -> datetime:
|
|||||||
day = int(day.split("/")[1])
|
day = int(day.split("/")[1])
|
||||||
|
|
||||||
# ensure that year rolls over if current month is December and the next month is less than 12.
|
# ensure that year rolls over if current month is December and the next month is less than 12.
|
||||||
if today.month == calendar.DECEMBER and month < calendar.DECEMBER:
|
if today.month == calendar.DECEMBER and month < calendar.OCTOBER:
|
||||||
year += 1
|
year += 1
|
||||||
|
|
||||||
if today.month == calendar.JANUARY and month > calendar.JANUARY:
|
if today.month == calendar.JANUARY and month > calendar.MARCH:
|
||||||
year -= 1
|
year -= 1
|
||||||
|
|
||||||
return datetime(year, month, day, tzinfo=UTC)
|
return datetime(year, month, day, tzinfo=UTC)
|
||||||
@@ -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()
|
cycle = get_active_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}"
|
||||||
|
|
||||||
@@ -82,7 +82,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() -> 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.
|
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:
|
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:
|
Returns:
|
||||||
int: cycle index for current cycle.
|
int: cycle index for current cycle.
|
||||||
|
|||||||
Reference in New Issue
Block a user