Start update_birthdays function.
build_develop / build (push) Successful in 1m24s

This commit is contained in:
2023-08-26 23:04:31 -04:00
parent df8cb3dd49
commit ac8d1bc681
2 changed files with 29 additions and 0 deletions
+28
View File
@@ -2,13 +2,18 @@
Defines the daily loop that runs the Dakiny bot functions.
"""
import random
from datetime import datetime, time
from nextcord.ext import commands, tasks
from pytz import timezone
from sqlalchemy import select
from sqlalchemy.orm import Session
from classes.election_cycle import ElectionCycle
from config import DakinyConfig
from dakiny_bot import birthday_list
from database_setup.sql_data_classes import UserBirthday, engine
from utils import get_datetime
@@ -26,6 +31,8 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
"""
Starts the loop when bot is ready.
"""
self.update_birthdays()
await self.bot.wait_until_ready()
# pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop.
await self.daily_loop.start() # pylint: disable=no-member
@@ -46,6 +53,8 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
if self.current_election.election_over:
self.current_election = None
self.update_birthdays()
def get_current_cycle(self) -> ElectionCycle:
"""
Creates an object for the current election cycle if one is active. An election is considered active
@@ -67,3 +76,22 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
current_election = ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
return current_election
def update_birthdays(self) -> None:
"""
Goes through database to collect all birthdays that are today. Adds user's id to birthday list.
"""
birthday_list.clear()
# kandy's 1% chance
if random.randint(0, 99) == 0:
birthday_list.append(239547993106284544)
today = datetime.today()
birthday = f"{today.month}/{today.day}"
stmt = select(UserBirthday.UserId).where(UserBirthday.Birthday == birthday)
with Session(engine) as session:
to_add = session.scalars(stmt)
print(to_add)
# TODO add the birthdays to the list
+1
View File
@@ -14,3 +14,4 @@ Base.prepare(autoload_with=engine)
ElectionInformation = Base.classes.ElectionInformation
CouncilMembers = Base.classes.CouncilMembers
Votes = Base.classes.Votes
UserBirthday = Base.classes.UserBirthday