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.6 KiB
Python

import discord
from redbot.core import commands, app_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=None,
api_key=None,
server_id=None
)
async def get_url(self, guild, endpoint = None):
"""Returns the base url for the Servers API, or the url for a specific endpoint if one is provided."""
if not await self.config.guild(guild).server_id():
raise LookupError("Server ID not set.")
elif not await self.config.guild(guild).base_url():
raise LookupError("Base URL not set.")
base_url = await self.config.guild(guild).base_url()
server_id = await self.config.guild(guild).server_id()
url = f"https://{base_url}/api/client/servers/{server_id}/"
if endpoint:
url += endpoint
return url
@app_commands.command()
async def test(self, interaction: discord.Interaction, endpoint: str = None):
"""This does stuff!"""
try:
if endpoint:
url = await self.get_url(interaction.guild, endpoint)
else:
url = await self.get_url(interaction.guild)
except LookupError as e:
await interaction.response.send_message(f"Something went wrong.\nError: `{e}`", ephemeral=True)
return
await interaction.response.send_message(url, ephemeral=True)