Compare commits
2 commits
55067cb269
...
2f8146d4f4
Author | SHA1 | Date | |
---|---|---|---|
2f8146d4f4 | |||
9be254e983 |
1 changed files with 7 additions and 5 deletions
|
@ -3,6 +3,7 @@ import aiohttp
|
||||||
import discord
|
import discord
|
||||||
import requests
|
import requests
|
||||||
from discord import ui
|
from discord import ui
|
||||||
|
from discord.ext import commands
|
||||||
from redbot.core import commands, app_commands, Config
|
from redbot.core import commands, app_commands, Config
|
||||||
|
|
||||||
class Pterodactyl(commands.Cog):
|
class Pterodactyl(commands.Cog):
|
||||||
|
@ -20,16 +21,16 @@ class Pterodactyl(commands.Cog):
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_url(self, guild, endpoint = None):
|
async def get_url(self, guild, endpoint = None):
|
||||||
"""Returns the base url for the Servers API, or the url for a specific API endpoint if one is provided."""
|
"""Returns the base url for the server's API, or the url for a specific API endpoint if one is provided."""
|
||||||
if await self.config.guild(guild).server_id() is None:
|
if await self.config.guild(guild).server_id() is None:
|
||||||
raise LookupError("Server ID not set.")
|
raise LookupError("Server ID not set.")
|
||||||
elif await self.config.guild(guild).base_url() is None:
|
elif await self.config.guild(guild).base_url() is None:
|
||||||
raise LookupError("Base URL not set.")
|
raise LookupError("Base URL not set.")
|
||||||
base_url = await self.config.guild(guild).base_url()
|
base_url = await self.config.guild(guild).base_url()
|
||||||
server_id = await self.config.guild(guild).server_id()
|
server_id = await self.config.guild(guild).server_id()
|
||||||
url = f"https://{base_url}/api/client/servers/{server_id}/"
|
url = f"https://{base_url}/api/client/servers/{server_id}"
|
||||||
if endpoint:
|
if endpoint:
|
||||||
url += endpoint
|
url += '/' + endpoint
|
||||||
return url
|
return url
|
||||||
|
|
||||||
async def put(self, url: str, headers: dict, data: dict):
|
async def put(self, url: str, headers: dict, data: dict):
|
||||||
|
@ -109,7 +110,8 @@ class Pterodactyl(commands.Cog):
|
||||||
"headers": headers,
|
"headers": headers,
|
||||||
"updater_startup_vars": updater_startup_vars,
|
"updater_startup_vars": updater_startup_vars,
|
||||||
"old_startup_vars": old_startup_vars,
|
"old_startup_vars": old_startup_vars,
|
||||||
"interaction": interaction
|
"interaction": interaction,
|
||||||
|
"interaction_context": await commands.Context.from_interaction(interaction),
|
||||||
}
|
}
|
||||||
await interaction_message.edit(content="The server is already running! Are you sure you'd like to stop the server for updates?", view=self.UpdateButtons(timeout=180, passed_info=passed_info))
|
await interaction_message.edit(content="The server is already running! Are you sure you'd like to stop the server for updates?", view=self.UpdateButtons(timeout=180, passed_info=passed_info))
|
||||||
|
|
||||||
|
@ -120,7 +122,7 @@ class Pterodactyl(commands.Cog):
|
||||||
|
|
||||||
@ui.button(label="Yes", style=discord.ButtonStyle.success)
|
@ui.button(label="Yes", style=discord.ButtonStyle.success)
|
||||||
async def yes_button(self, button:ui.Button, interaction:discord.Interaction):
|
async def yes_button(self, button:ui.Button, interaction:discord.Interaction):
|
||||||
requests.post(await Pterodactyl.get_url(self, interaction.guild, "power"), headers=self.passed_info['headers'], json={"signal": "stop"})
|
requests.post(await Pterodactyl.get_url(self, self.passed_info['interaction_context'].guild, "power"), headers=self.passed_info['headers'], json={"signal": "stop"})
|
||||||
await self.passed_info['interaction'].edit_original_response("Server stopping...", view=None)
|
await self.passed_info['interaction'].edit_original_response("Server stopping...", view=None)
|
||||||
while True:
|
while True:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
|
Reference in a new issue