This repository has been archived on 2024-03-07. You can view files and clone it, but cannot push or open issues or pull requests.
GalacticCogs/pterodactyl/ptero.py

40 lines
1.5 KiB
Python
Raw Normal View History

2023-07-14 11:04:58 -04:00
from redbot.core import commands, Config
class Pterodactyl(commands.Cog):
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=457581387213637448123567)
self.config.register_guild(
2023-07-14 11:17:38 -04:00
base_url=None,
2023-07-14 11:04:58 -04:00
api_key=None,
2023-07-14 11:16:03 -04:00
server_id=None
2023-07-14 11:04:58 -04:00
)
2023-07-14 11:11:42 -04:00
async def get_url(self, ctx, endpoint = None):
2023-07-14 11:04:58 -04:00
"""Returns the base url for the Servers API, or the url for a specific endpoint if one is provided."""
2023-07-14 11:11:42 -04:00
if not await self.config.guild(ctx.guild).server_id():
2023-07-14 11:04:58 -04:00
raise LookupError("Server ID not set.")
2023-07-14 11:16:03 -04:00
elif not await self.config.guild(ctx.guild).base_url():
raise LookupError("Base URL not set.")
2023-07-14 11:11:42 -04:00
base_url = await self.config.guild(ctx.guild).base_url()
server_id = await self.config.guild(ctx.guild).server_id()
2023-07-14 11:04:58 -04:00
url = f"https://{base_url}/api/client/servers/{server_id}/"
if endpoint:
url += endpoint
return url
@commands.command()
async def test(self, ctx, endpoint = None):
"""This does stuff!"""
2023-07-14 11:16:03 -04:00
try:
if endpoint:
url = await self.get_url(ctx, endpoint)
else:
url = await self.get_url(ctx)
except LookupError as e:
2023-07-14 11:17:38 -04:00
await ctx.send(f"Something went wrong.\nError: `{e}`")
return
2023-07-14 11:10:16 -04:00
await ctx.send(url)