Move all files into dakiny_bot package.

This commit is contained in:
2025-03-19 09:41:54 -04:00
parent 78d4b3d2de
commit 80dde1e8ed
29 changed files with 0 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Functions for controlling the bot's presence. Also contains the loop."""
import nextcord
from nextcord.ext import commands, tasks
from sqlalchemy import func, select
from sqlalchemy.orm import Session
from database_setup.sql_data_classes import Presences, engine
class BotPresence(commands.Cog, name="Bot Presence"):
"""Class for bot presence functions."""
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.Cog.listener()
async def on_guild_join(self, guild: nextcord.Guild) -> None: # noqa: ARG002
"""Listener for Guild Join. Updated presence on guild join."""
await self.change_presence()
@commands.Cog.listener()
async def on_ready(self) -> None:
"""Starts the loop when bot is ready."""
await self.bot.wait_until_ready()
self.periodic_change_presence.start()
@tasks.loop(minutes=5)
async def periodic_change_presence(self) -> None:
"""Loops every 5 minutes and changes presence."""
await self.change_presence()
async def change_presence(self) -> None:
"""Randomly chooses a presence and updates bot's presence."""
with Session(engine) as session:
presence = session.scalar(select(Presences.Presence).order_by(func.random()))
await self.bot.change_presence(activity=nextcord.CustomActivity(presence))