|
|
@@ -1,3 +1,4 @@
|
|
|
+const rollRegex = () => /\b(roll|flip)\b/i
|
|
|
const diceRegex = () => /\b(\d*)[dD](\d+)\b(?:\s?([+-])\s?(\d+))?/g
|
|
|
const rerollRegex = () => /\b(reroll|re-roll)\s+((?:(?:\S*|\d+s|\d+'s|\d+)\s*)+)/
|
|
|
const numberRegex = () => /\b(one|two|three|four|five|six|seven|eight|nine|ten|ones|twos|threes|fours|fives|sixes|sevens|eights|nines|tens|one's|two's|three's|four's|five's|seven's|eight's|nine's|ten's|\d+)\b/gi
|
|
|
@@ -48,7 +49,7 @@ const d10 = {
|
|
|
bonusText: (x) => {
|
|
|
const {percent = false, values = []} = x || {}
|
|
|
|
|
|
- if (values.length === 2 && !percent) return '_Did you mean "percentile"?_'
|
|
|
+ if (values.length === 2 && !percent) return '_Did you mean "roll percentile"?_'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -182,6 +183,8 @@ class Dice {
|
|
|
}
|
|
|
|
|
|
Dice.parse = (str, opts) => {
|
|
|
+ const rRegex = rollRegex()
|
|
|
+ const roll = rRegex.exec(str)
|
|
|
const rrRegex = rerollRegex()
|
|
|
const rerolls = []
|
|
|
const reroll = rrRegex.exec(str)
|
|
|
@@ -254,13 +257,16 @@ Dice.parse = (str, opts) => {
|
|
|
let dice
|
|
|
if (percent) {
|
|
|
ret.push(new Dice({
|
|
|
+ enabled: !!roll,
|
|
|
count: 2,
|
|
|
sides: 10,
|
|
|
- percent: true
|
|
|
+ percent: true,
|
|
|
+ rng: opts && opts.rng
|
|
|
}))
|
|
|
}
|
|
|
while (dice = regex.exec(str)) {
|
|
|
ret.push(new Dice({
|
|
|
+ enabled: !!roll,
|
|
|
match: dice,
|
|
|
count: dice[1] === '' ? 1 : parseFloat(dice[1]),
|
|
|
sides: parseFloat(dice[2]),
|
|
|
@@ -277,7 +283,7 @@ Dice.parse = (str, opts) => {
|
|
|
}
|
|
|
|
|
|
Dice.chat = (chat, opts) => {
|
|
|
- const dice = Dice.parse(chat, opts)
|
|
|
+ const dice = Dice.parse(chat, opts).filter(x => x.enabled)
|
|
|
if (dice.length) {
|
|
|
const diceStrings = dice.map(x => x.toString())
|
|
|
if (diceStrings.length > 1) {
|