import discord import aiohttp class Extension: def __init__(self, core): @core.tree.command(name = "rcon", description = "Вызвать команду на сервере") @discord.app_commands.describe(servers="Нужным сервер", command="Команда исполнения") @discord.app_commands.checks.has_role("Администратор Фактов13") @discord.app_commands.choices(servers = core.GetServersChoice()) async def rcon_command( interaction: discord.Interaction, servers: discord.app_commands.Choice[str], command: str ): await interaction.response.defer(thinking=True) steam64 = await core.GetSteam64OfDiscord(interaction.user) server = servers.value if not server in core.stats.get("servers", {}).keys(): return await interaction.followup.send(f"Сервер с таким индификатором не существует, введи существующий из предложенных:\n{' '.join(core.stats.get('servers', {}).keys())}", ephemeral=False) async with aiohttp.ClientSession(cookies={"secretkey":core.secret_key, "steam64":steam64}) as session: async with session.post(f"{core.backend_url}/api/admin/rcon?srv={server}&command={command}", ssl=False) as response: res = await response.text() if response.status == 200: return await interaction.followup.send(f'Ответ: {res}', ephemeral=False) else: return await interaction.followup.send('хуй тебе', ephemeral=False)