v1.0.0 #15
47
cogs/cog_utility.py
Normal file
47
cogs/cog_utility.py
Normal 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))
|
@@ -12,7 +12,7 @@
|
|||||||
"timezone": "UTC",
|
"timezone": "UTC",
|
||||||
"status": {
|
"status": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"activity_type": 0,
|
"activity_type": "playing",
|
||||||
"activity_text": "The Game Of Life"
|
"activity_text": "The Game Of Life"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user