55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import logging
|
|
|
|
from discord.ext import commands
|
|
|
|
from utils import about_me_embed
|
|
from utils import handle_api_request
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
# Setup function for the cog
|
|
async def setup(bot):
|
|
await bot.add_cog(Info(bot))
|
|
|
|
|
|
class Info(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
@commands.hybrid_command(
|
|
name="info_bot",
|
|
description="Displays information about the bot.",
|
|
aliases=["about", "bot_info"],
|
|
) # fun fact, commands can't start with cog_ or bot_
|
|
async def info_bot(self, ctx):
|
|
# see utils.py
|
|
embed = about_me_embed(self.bot)
|
|
await ctx.send(embed=embed, ephemeral=True)
|
|
|
|
@commands.hybrid_command(
|
|
name="servers", description="Fetches info about the game servers",
|
|
aliases=["server_list"]
|
|
)
|
|
async def servers(self, ctx):
|
|
result, message = handle_api_request("servers")
|
|
if result:
|
|
response = "Servers:"
|
|
for server in result:
|
|
name = server.get("name", "Unknown")
|
|
online_players = server.get("onlinePlayers", -1)
|
|
game_state = server.get("gameState", "Unknown")
|
|
map = server.get("mapAliasAndVersion", "Unknown")
|
|
game_settings = server.get("gameSettings", {})
|
|
max_players = game_settings.get("maxPlayers", -1)
|
|
response += f"\n* {name} - {game_state} - {map} - {online_players}/{max_players}"
|
|
await ctx.send(response, ephemeral=True)
|
|
else:
|
|
await ctx.send(f"Failed to retrieve server status: {message}", ephemeral=True)
|
|
|
|
@commands.command()
|
|
@commands.is_owner()
|
|
async def sync(self, ctx: commands.Context) -> None:
|
|
"""Sync commands"""
|
|
synced = await ctx.bot.tree.sync()
|
|
await ctx.send(f"Synced {len(synced)} commands for the server")
|