diff --git a/cogs/activity.py b/cogs/activity.py index 14cc256..a831942 100644 --- a/cogs/activity.py +++ b/cogs/activity.py @@ -3,9 +3,10 @@ Handles the activity displayed on the bot's Discord profile. The current intent is to display the server's player count as the activity. """ +import re import logging -from discord import Activity +from discord import Game from discord.ext import commands, tasks log = logging.getLogger(__name__) @@ -17,6 +18,7 @@ class ActivityCog(commands.Cog): """ def __init__(self, bot: commands.Bot): self.bot = bot + self.update_activity.start() @tasks.loop(seconds=30) async def update_activity(self): @@ -25,8 +27,15 @@ class ActivityCog(commands.Cog): """ log.debug("updating activity") - # self.bot. + players_message = await self.bot.rcon("players") + re_match = re.search(r"Players connected \((\d+)\):", players_message) + if not re_match: + log.error("Failed to parse player count from rcon response: %s", players_message) + return + + players_count = int(re_match.group(1)) + self.bot.activity = Game(name=f"**{players_count}**") async def setup(bot: commands.Bot):