From 65dac01c582c99e99b966122922de8504bfc36e6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 5 Sep 2019 20:32:22 +0200 Subject: [PATCH] Display a user friendly message on syntax errors --- royalnet/bots/discord.py | 3 +++ royalnet/bots/telegram.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/royalnet/bots/discord.py b/royalnet/bots/discord.py index 4b9660f7..776109e4 100644 --- a/royalnet/bots/discord.py +++ b/royalnet/bots/discord.py @@ -121,6 +121,9 @@ class DiscordBot(GenericBot): with message.channel.typing(): try: await command.run(CommandArgs(parameters), data=data) + except InvalidInputError as e: + await data.reply(f":warning: {' '.join(e.args)}\n" + f"Syntax: [c]/{command.name} {command.syntax}[/c]") except Exception as e: sentry_sdk.capture_exception(e) error_message = f"{e.__class__.__name__}\n" diff --git a/royalnet/bots/telegram.py b/royalnet/bots/telegram.py index 70ccbc0b..dee2d610 100644 --- a/royalnet/bots/telegram.py +++ b/royalnet/bots/telegram.py @@ -174,6 +174,9 @@ class TelegramBot(GenericBot): # Run the command try: await command.run(CommandArgs(parameters), data) + except InvalidInputError as e: + await data.reply(f"⚠️ {' '.join(e.args)}\n" + f"Syntax: [c]/{command.name} {command.syntax}[/c]") except Exception as e: sentry_sdk.capture_exception(e) error_message = f"⛔️ [b]{e.__class__.__name__}[/b]\n"