Compare commits

...
4 Commits
Author SHA1 Message Date
imcompiling 4f4d76d151 Feat: Add some logging.
build_develop / build (push) Successful in 43s
Trying to figure out why the elections are not starting.
2025-05-25 22:24:26 -04:00
imcompiling f3985b5d21 Feat: Set debug if env var is true. 2025-05-25 22:15:12 -04:00
imcompiling 142cc337a0 Feat: Add dakiny_bot logger. 2025-05-25 22:11:37 -04:00
imcompiling fd1d1c075e Feat: Remove logger from app.py. It existed it main.j 2025-05-25 22:11:18 -04:00
5 changed files with 34 additions and 10 deletions
-7
View File
@@ -1,6 +1,5 @@
"""Main file for bot."""
import logging
import os
import nextcord
@@ -16,12 +15,6 @@ from .DakinySettings import settings
birthday_list: list[int] = []
logger = logging.getLogger("nextcord")
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
logger.addHandler(handler)
def run() -> None:
"""Builds and runs bot."""
+12 -3
View File
@@ -5,9 +5,6 @@ from datetime import UTC, datetime, timedelta
from pathlib import Path
import nextcord
from sqlalchemy import select, true, update
from sqlalchemy.orm import Session
from dakiny_bot.classes.nominate_highcouncil_views import NominateHighCouncilView
from dakiny_bot.classes.nominate_views import NominateView
from dakiny_bot.classes.voting_highcouncil_views import VoteHighcouncilView
@@ -19,6 +16,7 @@ from dakiny_bot.database.sql_data_classes import (
Votes,
engine,
)
from dakiny_bot.logger import dakiny_logger
from dakiny_bot.utils import (
TEMPLATES_DIR,
VoteType,
@@ -28,6 +26,8 @@ from dakiny_bot.utils import (
get_datetime,
get_election_name,
)
from sqlalchemy import select, true, update
from sqlalchemy.orm import Session
REQUIRED_VOTES_TO_BE_ELECTED = 3
@@ -144,20 +144,29 @@ class Election:
async def check_date(self) -> None:
"""Function checks current date to see if something needs to be run."""
today = datetime.now(tz=UTC)
dakiny_logger.debug("Checking date.")
# check all dates if action is needed
if today.date() == self.election_start.date():
dakiny_logger.debug("Election start.")
await self.election_start_action()
elif today.date() == self.voting_start.date():
dakiny_logger.debug("Voting start.")
await self.voting_start_action()
elif (self.voting_end - timedelta(3)).date() <= today.date() < self.voting_end.date():
dakiny_logger.debug("Election reminder.")
await self.election_reminder()
elif today.date() == self.voting_end.date():
dakiny_logger.debug("Voting end.")
await self.voting_end_action()
elif today.date() == self.highcouncil_election_start.date():
dakiny_logger.debug("Highcouncil election start.")
await self.highcouncil_election_start_action()
elif today.date() == self.term_start.date():
dakiny_logger.debug("Term start")
await self.term_start_action()
else:
dakiny_logger.warning("Check date didn't do anything. This should never happen.")
async def election_start_action(self) -> None:
"""Performs required actions for when the election cycle starts."""
+5
View File
@@ -4,6 +4,7 @@ import random
from datetime import UTC, datetime, time
from typing import TYPE_CHECKING
from logger import dakiny_logger
from nextcord.ext import commands, tasks
from pytz import timezone
from sqlalchemy import select
@@ -43,8 +44,10 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
an active election, runs the check_date() function for the election to perform actions. Finally checks if the
election is over to delete the current election object.
"""
dakiny_logger.debug("Daily loop.")
if self.current_election is None:
self.current_election = self.get_election()
dakiny_logger.debug("Current election: %s", self.current_election)
if self.current_election is not None:
await self.current_election.check_date()
@@ -85,6 +88,8 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
election = Election(cycle, self.bot.get_guild(settings.params.guild_id))
dakiny_logger.debug("Election active: %s", election.active)
return election if election.active else None
def update_birthdays(self) -> None:
+11
View File
@@ -0,0 +1,11 @@
"""Creates logger for Dakiny bot."""
import logging
import os
import sys
dakiny_logger = logging.getLogger("default")
dakiny_logger.setLevel(logging.DEBUG if os.getenv("DEBUG") == "true" else logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
dakiny_logger.addHandler(handler)
+6
View File
@@ -20,6 +20,7 @@ from dakiny_bot.database.sql_data_classes import (
Votes,
engine,
)
from dakiny_bot.logger import dakiny_logger
from .DakinySettings import settings
@@ -92,12 +93,14 @@ def get_active_election_cycle() -> int:
int: cycle index for active election. None for no active cycle
"""
today = datetime.now(tz=UTC)
dakiny_logger.debug("Today is %s", today)
for cycle, election in enumerate(settings.election_cycles):
if (
today.date() >= get_datetime(election.election_start).date()
and today.date() <= get_datetime(election.term_start).date()
):
dakiny_logger.debug("Cycle is %d", cycle)
return cycle
# It isn't a current election, get the quarter
@@ -114,13 +117,16 @@ def get_quarter_cycle() -> int:
int: cycle index for current cycle.
"""
today = datetime.now(tz=UTC)
dakiny_logger.debug("Today is %s", today)
for cycle, election in enumerate(settings.election_cycles):
if (
today.date() >= get_datetime(election.term_start).date()
and today.date() <= get_datetime(election.term_end).date()
):
dakiny_logger.debug("Cycle is %d", cycle)
return cycle
dakiny_logger.debug("Quarter cycle is None.")
return None