1
0
mirror of https://github.com/MrDetonia/Maki.git synced 2024-11-22 03:44:18 -05:00

v1.0.10 accept dice rolls with optional dice number

This commit is contained in:
Zac Herd 2018-01-27 15:48:33 +00:00
parent d6f7638b2c
commit 998ec2bf3a
2 changed files with 14 additions and 2 deletions

View File

@ -134,6 +134,7 @@ def cmd_roll(client, msg):
tmp = msg.content[6:] tmp = msg.content[6:]
pattern = re.compile("^([0-9]+)d([0-9]+)$") pattern = re.compile("^([0-9]+)d([0-9]+)$")
pattern2 = re.compile("^d([0-9]+)$")
if pattern.match(tmp): if pattern.match(tmp):
# extract numbers # extract numbers
@ -149,8 +150,19 @@ def cmd_roll(client, msg):
rollsum += random.randint(1, nums[1]) rollsum += random.randint(1, nums[1])
response = "Using `{}d{}`, {} rolled: `{}`".format(nums[0], nums[1], msg.author.display_name, rollsum) response = "Using `{}d{}`, {} rolled: `{}`".format(nums[0], nums[1], msg.author.display_name, rollsum)
elif pattern2.match(tmp):
# extract number
num = [int(s) for s in re.findall(r"\d+", tmp)]
# limit range
num[0] = clamp(num[0], 1, 1000000)
# roll dice
roll = random.randint(1, num[0])
response = "Using `1d{}`, {} rolled `{}`".format(num[0], msg.author.display_name, roll)
else: else:
response = "Expected format: `<num>d<value>`" response = "Expected format: `[<num>]d<value>`"
yield from discord_send(client, msg, response) yield from discord_send(client, msg, response)

View File

@ -13,7 +13,7 @@ import json
# bot version # bot version
version = "v1.0.9" version = "v1.0.10"
# TODO: generate this on the fly and make it look acceptable # TODO: generate this on the fly and make it look acceptable