player count in activity
All checks were successful
Build and Push Docker Image / build (push) Successful in 13s
All checks were successful
Build and Push Docker Image / build (push) Successful in 13s
This commit is contained in:
parent
c291f486da
commit
271f067eb3
@ -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.
|
The current intent is to display the server's player count as the activity.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from discord import Activity
|
from discord import Game
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -17,6 +18,7 @@ class ActivityCog(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.update_activity.start()
|
||||||
|
|
||||||
@tasks.loop(seconds=30)
|
@tasks.loop(seconds=30)
|
||||||
async def update_activity(self):
|
async def update_activity(self):
|
||||||
@ -25,8 +27,15 @@ class ActivityCog(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
log.debug("updating activity")
|
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):
|
async def setup(bot: commands.Bot):
|
||||||
|
Reference in New Issue
Block a user