瀏覽代碼

v1.2.0, added modifiers to roll command

master
Zac Herd 5 年之前
父節點
當前提交
85a61eb7b4
共有 2 個文件被更改,包括 28 次插入12 次删除
  1. +27
    -11
      commands.py
  2. +1
    -1
      common.py

+ 27
- 11
commands.py 查看文件

@@ -137,8 +137,8 @@ def cmd_markov(client, msg):
def cmd_roll(client, msg):
tmp = msg.content[6:]

pattern = re.compile("^([0-9]+)d([0-9]+)$")
pattern2 = re.compile("^d([0-9]+)$")
pattern = re.compile("^(\d+)d(\d+)([+-]\d+)?$")
pattern2 = re.compile("^d(\d+)([+-]\d+)?$")

# extract numbers
nums = [int(s) for s in re.findall(r"\d+", tmp)]
@@ -150,9 +150,20 @@ def cmd_roll(client, msg):
numdice = 1
diceval = nums[0]
else:
response = "Expected format: `[<num>]d<value>`"
response = "Expected format: `[<num>]d<value>[{+-}<modifier>]`"
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
numdice = clamp(numdice, 1, 10)
diceval = clamp(diceval, 1, 1000)
@@ -162,20 +173,25 @@ def cmd_roll(client, msg):
for i in range(numdice):
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,
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)

if rollsum == numdice * diceval:
response += " *(Natural)*"
elif rollsum == numdice:
response += " *(Crit fail)*"
if rollsum - modifier == numdice * diceval:
response += " *(Natural - confirmed `{}`)*".format(
random.randint(1, 20))
elif rollsum - modifier == numdice:
response += " *(Crit fail - confirmed `{}`)*".format(
random.randint(1, 20))

yield from discord_send(client, msg, response)



+ 1
- 1
common.py 查看文件

@@ -10,7 +10,7 @@ import os
import json

# bot version
version = "v1.1.0"
version = "v1.2.0"

# TODO: generate this on the fly and make it look acceptable
# text shown by .help command


Loading…
取消
儲存