mirror of
https://github.com/MrDetonia/Maki.git
synced 2024-11-22 11:54:16 -05:00
v1.2.0, added modifiers to roll command
This commit is contained in:
parent
47fa9e95cf
commit
85a61eb7b4
38
commands.py
38
commands.py
@ -137,8 +137,8 @@ def cmd_markov(client, msg):
|
|||||||
def cmd_roll(client, msg):
|
def cmd_roll(client, msg):
|
||||||
tmp = msg.content[6:]
|
tmp = msg.content[6:]
|
||||||
|
|
||||||
pattern = re.compile("^([0-9]+)d([0-9]+)$")
|
pattern = re.compile("^(\d+)d(\d+)([+-]\d+)?$")
|
||||||
pattern2 = re.compile("^d([0-9]+)$")
|
pattern2 = re.compile("^d(\d+)([+-]\d+)?$")
|
||||||
|
|
||||||
# extract numbers
|
# extract numbers
|
||||||
nums = [int(s) for s in re.findall(r"\d+", tmp)]
|
nums = [int(s) for s in re.findall(r"\d+", tmp)]
|
||||||
@ -150,9 +150,20 @@ def cmd_roll(client, msg):
|
|||||||
numdice = 1
|
numdice = 1
|
||||||
diceval = nums[0]
|
diceval = nums[0]
|
||||||
else:
|
else:
|
||||||
response = "Expected format: `[<num>]d<value>`"
|
response = "Expected format: `[<num>]d<value>[{+-}<modifier>]`"
|
||||||
yield from discord_send(client, msg, response)
|
yield from discord_send(client, msg, response)
|
||||||
|
|
||||||
|
# extract modifier, if any
|
||||||
|
modifier = 0
|
||||||
|
modpattern = re.compile("^(\d+)?d(\d+)[+-]\d+$")
|
||||||
|
if modpattern.match(tmp):
|
||||||
|
modifier = nums[len(nums) - 1]
|
||||||
|
|
||||||
|
# negate modifier, if necessary
|
||||||
|
modpattern = re.compile("^(\d+)?d(\d+)[-]\d+$")
|
||||||
|
if modpattern.match(tmp):
|
||||||
|
modifier = -modifier
|
||||||
|
|
||||||
# limit ranges
|
# limit ranges
|
||||||
numdice = clamp(numdice, 1, 10)
|
numdice = clamp(numdice, 1, 10)
|
||||||
diceval = clamp(diceval, 1, 1000)
|
diceval = clamp(diceval, 1, 1000)
|
||||||
@ -162,20 +173,25 @@ def cmd_roll(client, msg):
|
|||||||
for i in range(numdice):
|
for i in range(numdice):
|
||||||
rolls.append(random.randint(1, diceval))
|
rolls.append(random.randint(1, diceval))
|
||||||
|
|
||||||
rollsum = sum(rolls)
|
rollsum = sum(rolls) + modifier
|
||||||
|
|
||||||
|
# generate response text
|
||||||
response = "**{} rolled:** {}d{}".format(msg.author.display_name, numdice,
|
response = "**{} rolled:** {}d{}".format(msg.author.display_name, numdice,
|
||||||
diceval)
|
diceval)
|
||||||
|
if modifier > 0:
|
||||||
|
response += "+{}".format(modifier)
|
||||||
|
if modifier < 0:
|
||||||
|
response += "{}".format(modifier)
|
||||||
|
|
||||||
if numdice > 1:
|
response += "\n**Rolls:** `{}`".format(rolls)
|
||||||
response += "\n**Rolls:** `{}`".format(rolls)
|
|
||||||
|
|
||||||
response += "\n**Result:** `{}`".format(rollsum)
|
response += "\n**Result:** `{}`".format(rollsum)
|
||||||
|
|
||||||
if rollsum == numdice * diceval:
|
if rollsum - modifier == numdice * diceval:
|
||||||
response += " *(Natural)*"
|
response += " *(Natural - confirmed `{}`)*".format(
|
||||||
elif rollsum == numdice:
|
random.randint(1, 20))
|
||||||
response += " *(Crit fail)*"
|
elif rollsum - modifier == numdice:
|
||||||
|
response += " *(Crit fail - confirmed `{}`)*".format(
|
||||||
|
random.randint(1, 20))
|
||||||
|
|
||||||
yield from discord_send(client, msg, response)
|
yield from discord_send(client, msg, response)
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
# bot version
|
# bot version
|
||||||
version = "v1.1.0"
|
version = "v1.2.0"
|
||||||
|
|
||||||
# TODO: generate this on the fly and make it look acceptable
|
# TODO: generate this on the fly and make it look acceptable
|
||||||
# text shown by .help command
|
# text shown by .help command
|
||||||
|
Loading…
Reference in New Issue
Block a user