Fix birthday loop.
build_develop / build (push) Failing after 17s

This commit is contained in:
2025-03-17 17:51:28 -04:00
parent eef85b424d
commit bbacaa8bb9
3 changed files with 17 additions and 11 deletions
+1
View File
@@ -5,6 +5,7 @@
"reportAttributeAccessIssue": "warning"
},
"cSpell.words": [
"cakeday",
"cakedays"
]
}
+12 -11
View File
@@ -1,20 +1,20 @@
"""Defines the daily loop that runs the Dakiny bot functions."""
"""Defines the daily loop that runs the Off Cooldown bot functions."""
from datetime import UTC, datetime, time
from typing import TYPE_CHECKING
import nextcord
from nextcord.ext import commands, tasks
from pytz import timezone
from sqlalchemy import select
from sqlalchemy.orm import Session
from sqlmodel import col
from database.db import engine
from database.models import UserBirthday
from logger import ocd_logger
from main import birthday_list
from settings import settings
if TYPE_CHECKING:
import nextcord
class DailyLoop(commands.Cog, name="Daily Loop"):
"""Class for performing daily functions."""
@@ -23,9 +23,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
self.bot = bot
self.current_election = None
self.update_birthdays()
# pylint doesn't recognize that daily_loop is subclassed from tasks.loop.
self.daily_loop.start() # pylint: disable=no-member
self.daily_loop.start()
@tasks.loop(time=time(hour=0, tzinfo=timezone("UTC")))
async def daily_loop(self) -> None:
@@ -44,9 +42,12 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
birthday_list.clear()
today = datetime.now(tz=UTC).date()
birthday = f"{today.month}/{today.day}"
stmt = select(UserBirthday.UserId).where(UserBirthday.Birthday == birthday)
stmt = (
select(col(UserBirthday.user_id))
.where(col(UserBirthday.month) == today.month)
.where(col(UserBirthday.day) == today.day)
)
with Session(engine) as session:
to_add = session.scalars(stmt)
birthday_list.extend(to_add.all())
@@ -74,7 +75,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
]
for member in cakedays:
years = today.year - member.joined_at.year
years = today.year - member.joined_at.year # type: ignore reportOptionalMemberAccess
year_str = "years" if years > 1 else "year"
msg = f"Happy Cake day! <@{member.id}> joined the discord {years} {year_str} ago!"
await announce_channel.send(msg)
+4
View File
@@ -1,5 +1,7 @@
"""Main file for bot."""
from __future__ import annotations
import logging
import pathlib
@@ -15,6 +17,8 @@ nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8"
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
nextcord_logger.addHandler(nextcord_handler)
birthday_list: list[int] = []
def main() -> None:
"""Set config, intents, then connects the bot to discord."""