player count in activity
All checks were successful
Build and Push Docker Image / build (push) Successful in 13s

This commit is contained in:
Corban-Lee Jones 2024-12-06 11:35:10 +00:00
parent c291f486da
commit 271f067eb3

View File

@ -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):