feat: added PowerButtons class

This commit is contained in:
Seaswimmer 2023-07-16 13:25:31 -04:00
parent dbd16175a6
commit 9bb23e6faf
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -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.")