Fixed more error handling

+ I hate discord.py sometimes
master
Joey Hines 2019-10-11 16:49:00 -05:00
parent 17c11d482b
commit bc6a77257f
2 changed files with 20 additions and 12 deletions

View File

@ -88,8 +88,11 @@ class GeoffreyBot(commands.Bot):
return
elif isinstance(error, commands.errors.CommandNotFound):
return
elif isinstance(error, commands.errors.ExpectedClosingQuoteError):
elif isinstance(error, commands.errors.ExpectedClosingQuoteError) or isinstance(error,
commands.errors.UnexpectedQuoteError):
error_str = "It appears you are missing a quotation mark in there, better luck next time goober."
elif isinstance(error, commands.errors.InvalidEndOfQuotedStringError):
error_str = "You need a space after that quotation mark bud."
elif isinstance(error, commands.errors.BadArgument) or isinstance(error, commands.MissingRequiredArgument) or (
hasattr(error, "original") and isinstance(error.original, ValueError)):
error_str = "Well bud, you got this far. Good job! But you still h*cked up the syntax:"
@ -100,7 +103,10 @@ class GeoffreyBot(commands.Bot):
error_str = "Unable to connect to the database. Hopefully someone is working on this..."
await self.send_error_message("Can't connect to the GeoffreyAPI, is it offline?")
elif hasattr(error, "original"):
e = error.original.args[0]
if len(error.original.args):
e = error.original.args[0]
else:
e = None
if e == "TypeError":
error_str = "Well bud, you got this far. Good job! But you still h*cked up the syntax:"
@ -120,9 +126,14 @@ class GeoffreyBot(commands.Bot):
ctx.invoked_with,
command_args))
if hasattr(error, "original"):
tb = traceback.format_tb(error.original.__traceback__)
else:
tb = traceback.format_tb(error.__traceback__)
error_message = ["```python"]
for tb in traceback.format_tb(error.original.__traceback__):
error_message.append(tb)
for line in tb:
error_message.append(line)
error_message.append("```")
@ -131,6 +142,8 @@ class GeoffreyBot(commands.Bot):
logger.error("Geoffrey encountered exception: %s", error)
traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
await self.send_error_message(error_message)
await ctx.message.channel.send('{} **Error Running Command:** {}'.format(
ctx.message.author.mention, error_str))
@ -151,16 +164,11 @@ class GeoffreyBot(commands.Bot):
if user is None:
continue
if msg is list:
if isinstance(msg, list):
await self.send_list(user, msg)
else:
await user.send(msg)
def run_command(self, command, **kwargs):
url = self.base_url + '/api/command/{}'
return requests.get(url=url.format(command), params=kwargs).json()
@staticmethod
async def send_formatted_message(ctx, msg_format, *args, ping_user=False):
if ping_user:

View File

@ -299,7 +299,7 @@ class GeoffreyCommands(commands.Cog):
errors = {
"LocationLookUpError": "you do not have a farm by that name you ding dong goober.",
"EntryNameNotUniqueError": "you have more than one location. Please specify a name, dingus.",
"ItemNotFound": "your farm does not produce **{}**. Try again buddy boy.".format(resource_name)
"ResourceNotFound": "your farm does not produce **{}**. Try again buddy boy.".format(resource_name)
}
farm = await run_command(ctx, self.api_url, self.api_token, "POST", "delete_resource", errors=errors,
@ -371,7 +371,7 @@ class GeoffreyCommands(commands.Cog):
location["tunnel"]))
@commands.command(pass_context=True)
async def find_around(self, ctx, x_pos, z_pos, *args):
async def find_around(self, ctx, x_pos: int, z_pos: int, *args):
"""
{}find_around <X Coordinate> <Z Coordinate> <Radius>
The Radius parameter is optional and defaults to 200 blocks