RC2Bot/cogs/info.py

56 lines
1.8 KiB
Python
Raw Permalink Normal View History

2024-10-09 23:25:22 +00:00
import logging
2024-10-10 22:34:33 +00:00
from discord.ext import commands
2024-10-09 23:25:22 +00:00
from utils import about_me_embed
2024-10-10 22:34:33 +00:00
from utils import handle_api_request
2024-10-09 23:25:22 +00:00
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)
2024-10-10 22:34:33 +00:00
await ctx.send(embed=embed, ephemeral=True)
2024-10-09 23:25:22 +00:00
@commands.hybrid_command(
2024-10-10 22:34:33 +00:00
name="servers", description="Fetches info about the game servers",
aliases=["server_list"]
2024-10-09 23:25:22 +00:00
)
2024-10-10 22:34:33 +00:00
async def servers(self, ctx):
result, message = handle_api_request("servers")
2024-10-09 23:25:22 +00:00
if result:
2024-10-10 22:34:33 +00:00
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)
2024-10-09 23:25:22 +00:00
else:
2024-10-10 22:34:33 +00:00
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")