from logging import Logger from discord import Activity, ActivityType, Cog, Member 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 @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) # TODO Implement #11 @Cog.listener() async def on_member_join(self, member: Member) -> None: pass def setup(bot: PycordBot) -> None: bot.add_cog(CogUtility(bot))