From 998ec2bf3ae9cb3daa2ee57b64387e591224bec8 Mon Sep 17 00:00:00 2001 From: Zac Herd Date: Sat, 27 Jan 2018 15:48:33 +0000 Subject: [PATCH] v1.0.10 accept dice rolls with optional dice number --- commands.py | 14 +++++++++++++- common.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/commands.py b/commands.py index 7d180a8..12d46a7 100755 --- a/commands.py +++ b/commands.py @@ -134,6 +134,7 @@ def cmd_roll(client, msg): tmp = msg.content[6:] pattern = re.compile("^([0-9]+)d([0-9]+)$") + pattern2 = re.compile("^d([0-9]+)$") if pattern.match(tmp): # extract numbers @@ -149,8 +150,19 @@ def cmd_roll(client, msg): rollsum += random.randint(1, nums[1]) 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: - response = "Expected format: `d`" + response = "Expected format: `[]d`" yield from discord_send(client, msg, response) diff --git a/common.py b/common.py index 2bf967f..708a788 100755 --- a/common.py +++ b/common.py @@ -13,7 +13,7 @@ import json # bot version -version = "v1.0.9" +version = "v1.0.10" # TODO: generate this on the fly and make it look acceptable