This commit is contained in:
@@ -143,7 +143,7 @@ class ElectionCycle:
|
|||||||
|
|
||||||
async def check_date(self) -> None:
|
async def check_date(self) -> None:
|
||||||
"""Function checks current date to see if something needs to be run."""
|
"""Function checks current date to see if something needs to be run."""
|
||||||
today = datetime.now(tz=UTC).date()
|
today = datetime.now(tz=UTC)
|
||||||
|
|
||||||
# check all dates if action is needed
|
# check all dates if action is needed
|
||||||
if today.date() == self.election_start.date():
|
if today.date() == self.election_start.date():
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class SetCog(commands.Cog, name="Set Commands"):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# check if valid day
|
# check if valid day
|
||||||
today = datetime.now(tz=UTC).date()
|
today = datetime.now(tz=UTC)
|
||||||
try:
|
try:
|
||||||
birthday = datetime(today.year, month, day, tzinfo=UTC)
|
birthday = datetime(today.year, month, day, tzinfo=UTC)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import application_checks, commands
|
from nextcord.ext import application_checks, commands
|
||||||
from nextcord.ext.application_checks.core import AC
|
|
||||||
|
|
||||||
from classes.election_cycle import ElectionCycle
|
from classes.election_cycle import ElectionCycle
|
||||||
from utils import get_current_election_cycle
|
from utils import get_current_election_cycle
|
||||||
@@ -17,7 +16,7 @@ ME = 206602713511886849
|
|||||||
GUILDS = [1000247361639030804]
|
GUILDS = [1000247361639030804]
|
||||||
|
|
||||||
|
|
||||||
def is_me() -> AC:
|
def is_me(): # noqa: ANN201
|
||||||
"""Predicate that makes sure only I can run the test commands."""
|
"""Predicate that makes sure only I can run the test commands."""
|
||||||
|
|
||||||
def predicate(interaction: nextcord.Interaction) -> bool:
|
def predicate(interaction: nextcord.Interaction) -> bool:
|
||||||
@@ -53,7 +52,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_start_action()
|
await cycle.election_start_action()
|
||||||
await interaction.send("Test command sent.")
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
@is_me()
|
@is_me()
|
||||||
@@ -71,7 +70,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_start_action()
|
await cycle.voting_start_action()
|
||||||
await interaction.send("Test command sent.")
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
@is_me()
|
@is_me()
|
||||||
@@ -89,7 +88,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_end_action()
|
await cycle.voting_end_action()
|
||||||
await interaction.send("Test command sent.")
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
@is_me()
|
@is_me()
|
||||||
@@ -107,7 +106,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.highcouncil_election_start_action()
|
await cycle.highcouncil_election_start_action()
|
||||||
await interaction.send("Test command sent.")
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
@is_me()
|
@is_me()
|
||||||
@@ -125,7 +124,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_reminder()
|
await cycle.election_reminder()
|
||||||
await interaction.send("Test command sent.")
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
@is_me()
|
@is_me()
|
||||||
@@ -143,7 +142,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.check_date()
|
await cycle.check_date()
|
||||||
await interaction.send("Test command sent.")
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
@is_me()
|
@is_me()
|
||||||
@@ -161,4 +160,4 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.term_start_action()
|
await cycle.term_start_action()
|
||||||
await interaction.send("Test command sent.")
|
await interaction.send("Test command sent.", ephemeral=True)
|
||||||
|
|||||||
@@ -47,10 +47,12 @@ 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:
|
# TODO(imcompiling): replace with Calendar.DECEMBER when updating to python 3.12
|
||||||
|
# https://gitea.cheezers.org/imcompiling/dakiny-bot/issues/52
|
||||||
|
if today.month == 12 and month < 12:
|
||||||
year += 1
|
year += 1
|
||||||
|
|
||||||
if today.month == calendar.JANUARY and month > calendar.JANUARY:
|
if today.month == 1 and month > 1:
|
||||||
year -= 1
|
year -= 1
|
||||||
|
|
||||||
return datetime(year, month, day, tzinfo=UTC)
|
return datetime(year, month, day, tzinfo=UTC)
|
||||||
@@ -97,7 +99,7 @@ def get_current_election_cycle(config: DakinyConfig) -> int:
|
|||||||
Returns:
|
Returns:
|
||||||
int: cycle index for active election. None for no active cycle
|
int: cycle index for active election. None for no active cycle
|
||||||
"""
|
"""
|
||||||
today = datetime.now(tz=UTC).date()
|
today = datetime.now(tz=UTC)
|
||||||
|
|
||||||
for cycle, election in enumerate(config.election_cycles):
|
for cycle, election in enumerate(config.election_cycles):
|
||||||
if (
|
if (
|
||||||
@@ -120,7 +122,7 @@ def get_quarter_cycle(config: DakinyConfig) -> int:
|
|||||||
Returns:
|
Returns:
|
||||||
int: cycle index for current cycle.
|
int: cycle index for current cycle.
|
||||||
"""
|
"""
|
||||||
today = datetime.now(tz=UTC).date()
|
today = datetime.now(tz=UTC)
|
||||||
for cycle, election in enumerate(config.election_cycles):
|
for cycle, election in enumerate(config.election_cycles):
|
||||||
if (
|
if (
|
||||||
today.date() >= get_datetime(election.term_start).date()
|
today.date() >= get_datetime(election.term_start).date()
|
||||||
|
|||||||
Reference in New Issue
Block a user