Implemented activities

This commit is contained in:
2025-04-26 21:31:35 +02:00
parent e45a56835a
commit 6b143d8a2d
2 changed files with 48 additions and 1 deletions

47
cogs/cog_utility.py Normal file
View File

@@ -0,0 +1,47 @@
from logging import Logger
from discord import Activity, ActivityType, Cog
from discord.ext import commands
from classes.pycord_bot import PycordBot
from modules.utils import get_logger
logger: Logger = get_logger(__name__)
class CogUtility(Cog):
def __init__(self, bot: PycordBot):
self.bot: PycordBot = bot
@commands.Cog.listener()
async def on_ready(self) -> None:
"""Listener for the event when bot connects to Discord and becomes "ready"."""
logger.info("Logged in as %s", self.bot.user)
activity_enabled: bool = self.bot.config["bot"]["status"]["enabled"]
activity_type: str = self.bot.config["bot"]["status"]["activity_type"]
activity_message: str = self.bot.config["bot"]["status"]["activity_text"]
if not activity_enabled:
return
if activity_type == "playing":
await self.bot.change_presence(activity=Activity(type=ActivityType.playing, name=activity_message))
elif activity_type == "watching":
await self.bot.change_presence(activity=Activity(type=ActivityType.watching, name=activity_message))
elif activity_type == "listening":
await self.bot.change_presence(activity=Activity(type=ActivityType.listening, name=activity_message))
elif activity_type == "streaming":
await self.bot.change_presence(activity=Activity(type=ActivityType.streaming, name=activity_message))
elif activity_type == "competing":
await self.bot.change_presence(activity=Activity(type=ActivityType.competing, name=activity_message))
elif activity_type == "custom":
await self.bot.change_presence(activity=Activity(type=ActivityType.custom, name=activity_message))
else:
return
logger.info("Set activity type to %s with message %s", activity_type, activity_message)
def setup(bot: PycordBot) -> None:
bot.add_cog(CogUtility(bot))