improved error handling

This commit is contained in:
Seaswimmer 2023-07-14 11:16:03 -04:00
parent 4016e92ad9
commit f552929570
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -7,15 +7,17 @@ class Pterodactyl(commands.Cog):
self.bot = bot self.bot = bot
self.config = Config.get_conf(self, identifier=457581387213637448123567) self.config = Config.get_conf(self, identifier=457581387213637448123567)
self.config.register_guild( self.config.register_guild(
base_url="pterodactyl.file.properties", base_url="mc.bloom.host",
api_key=None, api_key=None,
server_id="d6d05b41-4da5-4c5b-9ee6-6e25f61a596b" server_id=None
) )
async def get_url(self, ctx, endpoint = None): async 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.""" """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(ctx.guild).server_id(): if not await self.config.guild(ctx.guild).server_id():
raise LookupError("Server ID not set.") raise LookupError("Server ID not set.")
elif not await self.config.guild(ctx.guild).base_url():
raise LookupError("Base URL not set.")
base_url = await self.config.guild(ctx.guild).base_url() base_url = await self.config.guild(ctx.guild).base_url()
server_id = await self.config.guild(ctx.guild).server_id() server_id = await self.config.guild(ctx.guild).server_id()
url = f"https://{base_url}/api/client/servers/{server_id}/" url = f"https://{base_url}/api/client/servers/{server_id}/"
@ -26,9 +28,11 @@ class Pterodactyl(commands.Cog):
@commands.command() @commands.command()
async def test(self, ctx, endpoint = None): async def test(self, ctx, endpoint = None):
"""This does stuff!""" """This does stuff!"""
# Your code will go here try:
if endpoint: if endpoint:
url = await self.get_url(ctx, endpoint) url = await self.get_url(ctx, endpoint)
else: else:
url = await self.get_url(ctx) url = await self.get_url(ctx)
except LookupError as e:
await ctx.send(f"Something went wrong.\n{e}")
await ctx.send(url) await ctx.send(url)