mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-12-03 16:24:20 +00:00
Don't raise an error for invalid roll inputs
This commit is contained in:
parent
f425be7c95
commit
403e969708
1 changed files with 16 additions and 9 deletions
|
@ -15,6 +15,7 @@ class RollCommand(Command):
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
first: typing.Optional[str] = args.optional(0)
|
first: typing.Optional[str] = args.optional(0)
|
||||||
second: typing.Optional[str] = args.optional(1)
|
second: typing.Optional[str] = args.optional(1)
|
||||||
|
try:
|
||||||
if second:
|
if second:
|
||||||
minimum = int(first)
|
minimum = int(first)
|
||||||
maximum = int(second)
|
maximum = int(second)
|
||||||
|
@ -24,5 +25,11 @@ class RollCommand(Command):
|
||||||
else:
|
else:
|
||||||
minimum = 1
|
minimum = 1
|
||||||
maximum = 100
|
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)
|
result = random.randrange(minimum, maximum+1)
|
||||||
await data.reply(f"🎲 Dice roll [{minimum}-{maximum}]: [b]{result}[/b]")
|
await data.reply(f"🎲 Dice roll [{minimum}-{maximum}]: [b]{result}[/b]")
|
||||||
|
|
Loading…
Reference in a new issue