roll: allow junk at end of line
This enables "fun" stuff like "!roll 20 bottles of milk"
This commit is contained in:
parent
76266d8d2f
commit
d275da418f
1 changed files with 23 additions and 19 deletions
|
|
@ -17,12 +17,9 @@ def init(bot):
|
|||
|
||||
|
||||
async def handle(message: Message):
|
||||
if len(message.args) == 1 and message.args[0].isdecimal():
|
||||
dice = [(1, int(message.args[0]))]
|
||||
else:
|
||||
dice = []
|
||||
num = None
|
||||
for arg in message.args:
|
||||
for consumed, arg in enumerate(message.args, start=1):
|
||||
if (match := parse_die(arg)) :
|
||||
if num and match["num"]:
|
||||
return
|
||||
|
|
@ -36,7 +33,10 @@ async def handle(message: Message):
|
|||
return
|
||||
num = int(arg)
|
||||
else:
|
||||
return
|
||||
consumed -= 1
|
||||
break
|
||||
if not dice and num:
|
||||
dice.append((1, num))
|
||||
|
||||
if not 0 < len(dice) < 20:
|
||||
return
|
||||
|
|
@ -56,4 +56,8 @@ async def handle(message: Message):
|
|||
for sides, vs in sorted(rolls.items(), key=lambda i: i[0], reverse=1)
|
||||
)
|
||||
text = f"{total} = {dicestr}"
|
||||
|
||||
if len(message.args) > consumed:
|
||||
text += " " + " ".join(message.args[consumed:])
|
||||
|
||||
await reply(message, plain=text, in_thread=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue