Archived
generated from imcompiling/discord-bot-template
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""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))
|
||||
Reference in New Issue
Block a user