From 9bb23e6faf7cd5c93604a8fd6bebf8d467fa6513 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 16 Jul 2023 13:25:31 -0400 Subject: [PATCH] feat: added PowerButtons class --- pterodactyl/ptero.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pterodactyl/ptero.py b/pterodactyl/ptero.py index ba7834e..6da9f30 100644 --- a/pterodactyl/ptero.py +++ b/pterodactyl/ptero.py @@ -180,6 +180,34 @@ class Pterodactyl(commands.Cog): message = await self.passed_info['interaction'].edit_original_response(content=f"Command cancelled.", view=None) await message.delete(delay=3) + class PowerButtons(ui.View): + def __init__(self, timeout, passed_info): + super().__init__() + self.passed_info = passed_info + self.config = Config.get_conf(None, cog_name='Pterodactyl', identifier=457581387213637448123567) + + @ui.button(label="Yes", style=discord.ButtonStyle.success) + async def yes_button(self, button:ui.Button, interaction:discord.Interaction): + headers = self.passed_info['headers'] + requests.post(await Pterodactyl.get_url(self, self.passed_info['guild'], "power"), headers=headers, json={"signal": self.passed_info['signal']}) + message = await self.passed_info['interaction'].edit_original_response(content=self.passed_info['message'], view=None) + while True: + async with aiohttp.ClientSession() as session: + async with session.get(await Pterodactyl.get_url(self, self.passed_info['guild'], "resources"), headers=headers) as response: + response_dict = await response.json() + if response_dict['attributes']['current_state'] == self.passed_info['target_signal']: + await message.edit(content=self.passed_info['completed_message']) + break + else: + await asyncio.sleep(1) + continue + + @ui.button(label="No", style=discord.ButtonStyle.danger) + async def no_button(self, button:ui.Button, interaction:discord.Interaction): + message = await self.passed_info['interaction'].edit_original_response(content=f"Command cancelled.", view=None) + await message.delete(delay=3) + + get_group = app_commands.Group(name='get', description="Retrieves information from the Pterodactyl API.") @get_group.command(name='url', description="Retrieves the URL for the specified endpoint.")