From 403e9697080675c29076755fe24e7a2aa8b8801c Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 2 Apr 2020 18:29:51 +0200 Subject: [PATCH] Don't raise an error for invalid roll inputs --- rpgpack/commands/roll.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/rpgpack/commands/roll.py b/rpgpack/commands/roll.py index bb69dd8f..54d48ee7 100644 --- a/rpgpack/commands/roll.py +++ b/rpgpack/commands/roll.py @@ -15,14 +15,21 @@ class RollCommand(Command): async def run(self, args: CommandArgs, data: CommandData) -> None: first: typing.Optional[str] = args.optional(0) second: typing.Optional[str] = args.optional(1) - if second: - minimum = int(first) - maximum = int(second) - elif first: - minimum = 1 - maximum = int(first) - else: - minimum = 1 - maximum = 100 + try: + if second: + minimum = int(first) + maximum = int(second) + elif first: + minimum = 1 + maximum = int(first) + else: + minimum = 1 + maximum = 100 + except ValueError: + if isinstance(first, str) and "d20" in first: + raise InvalidInputError(f"Invalid value specified.\n" + f"Were you looking for [c]{self.interface.prefix}dice[/c]?") + else: + raise InvalidInputError("Invalid value specified.") result = random.randrange(minimum, maximum+1) await data.reply(f"🎲 Dice roll [{minimum}-{maximum}]: [b]{result}[/b]")