This repository has been archived on 2025-04-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
off-cooldown-bot/cogs/loops/bot_presence.py
T

45 lines
1.3 KiB
Python

"""Functions for controlling the bot's presence. Also contains the loop."""
import random
import nextcord
from nextcord.ext import commands, tasks
class BotPresence(commands.Cog, name="Bot Presence"):
"""Class for bot presence functions."""
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@commands.Cog.listener()
async def on_ready(self) -> None:
"""Start the loop when bot is ready."""
await self.bot.wait_until_ready()
self.periodic_change_presence.start()
@tasks.loop(minutes=30)
async def periodic_change_presence(self) -> None:
"""Loops every 30 minutes and changes presence."""
await self.change_presence()
async def change_presence(self) -> None:
"""Randomly chooses a presence and updates bot's presence."""
dungeons = [
"Cinderbrew Meadery",
"Darkflame Cleft",
"The Rookery",
"Priory of the Sacred Flame",
"Operation: Floodgate",
"The MOTHERLODE!!",
"Theater of Pain",
"Operation: Mechagon - Workshop",
]
dungeon = random.choice(dungeons) # noqa: S311
plus = random.randint(2, 12) # noqa: S311
presence = f"Running +{plus} {dungeon}"
await self.bot.change_presence(activity=nextcord.CustomActivity(presence))