34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
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(
|
|
base_url="pterodactyl.file.properties",
|
|
api_key=None,
|
|
server_id="d6d05b41-4da5-4c5b-9ee6-6e25f61a596b"
|
|
)
|
|
|
|
def get_url(self, ctx, endpoint = None):
|
|
"""Returns the base url for the Servers API, or the url for a specific endpoint if one is provided."""
|
|
if not self.config.guild(ctx.guild).server_id():
|
|
raise LookupError("Server ID not set.")
|
|
base_url = self.config.guild(ctx.guild).base_url()
|
|
server_id = self.config.guild(ctx.guild).server_id()
|
|
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!"""
|
|
# Your code will go here
|
|
if endpoint:
|
|
url = self.get_url(ctx, endpoint)
|
|
else:
|
|
url = self.get_url(ctx)
|
|
await ctx.send(url)
|