mirror of
https://github.com/MrDetonia/Maki.git
synced 2024-11-22 11:54:16 -05:00
v1.0.10 accept dice rolls with optional dice number
This commit is contained in:
parent
d6f7638b2c
commit
998ec2bf3a
14
commands.py
14
commands.py
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user