Archived
generated from imcompiling/discord-bot-template
Vendored
+1
@@ -5,6 +5,7 @@
|
|||||||
"reportAttributeAccessIssue": "warning"
|
"reportAttributeAccessIssue": "warning"
|
||||||
},
|
},
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
|
"cakeday",
|
||||||
"cakedays"
|
"cakedays"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+12
-11
@@ -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 datetime import UTC, datetime, time
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
|
import nextcord
|
||||||
from nextcord.ext import commands, tasks
|
from nextcord.ext import commands, tasks
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
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 logger import ocd_logger
|
||||||
from main import birthday_list
|
from main import birthday_list
|
||||||
from settings import settings
|
from settings import settings
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
import nextcord
|
|
||||||
|
|
||||||
|
|
||||||
class DailyLoop(commands.Cog, name="Daily Loop"):
|
class DailyLoop(commands.Cog, name="Daily Loop"):
|
||||||
"""Class for performing daily functions."""
|
"""Class for performing daily functions."""
|
||||||
@@ -23,9 +23,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.current_election = None
|
self.current_election = None
|
||||||
self.update_birthdays()
|
self.update_birthdays()
|
||||||
|
self.daily_loop.start()
|
||||||
# pylint doesn't recognize that daily_loop is subclassed from tasks.loop.
|
|
||||||
self.daily_loop.start() # pylint: disable=no-member
|
|
||||||
|
|
||||||
@tasks.loop(time=time(hour=0, tzinfo=timezone("UTC")))
|
@tasks.loop(time=time(hour=0, tzinfo=timezone("UTC")))
|
||||||
async def daily_loop(self) -> None:
|
async def daily_loop(self) -> None:
|
||||||
@@ -44,9 +42,12 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
birthday_list.clear()
|
birthday_list.clear()
|
||||||
|
|
||||||
today = datetime.now(tz=UTC).date()
|
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:
|
with Session(engine) as session:
|
||||||
to_add = session.scalars(stmt)
|
to_add = session.scalars(stmt)
|
||||||
birthday_list.extend(to_add.all())
|
birthday_list.extend(to_add.all())
|
||||||
@@ -74,7 +75,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
]
|
]
|
||||||
|
|
||||||
for member in cakedays:
|
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"
|
year_str = "years" if years > 1 else "year"
|
||||||
msg = f"Happy Cake day! <@{member.id}> joined the discord {years} {year_str} ago!"
|
msg = f"Happy Cake day! <@{member.id}> joined the discord {years} {year_str} ago!"
|
||||||
await announce_channel.send(msg)
|
await announce_channel.send(msg)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
"""Main file for bot."""
|
"""Main file for bot."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import pathlib
|
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_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
||||||
nextcord_logger.addHandler(nextcord_handler)
|
nextcord_logger.addHandler(nextcord_handler)
|
||||||
|
|
||||||
|
birthday_list: list[int] = []
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""Set config, intents, then connects the bot to discord."""
|
"""Set config, intents, then connects the bot to discord."""
|
||||||
|
|||||||
Reference in New Issue
Block a user