From e200efba6ea606cfc4ef45c2059371e474ea0ba1 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 12 Feb 2024 18:13:26 +0200 Subject: [PATCH] allow ppl to choose the size of roll --- files/helpers/regex.py | 14 ++++++++------ files/templates/formatting.html | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 0f391af52..248574823 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -1,6 +1,6 @@ import random import re -from random import choice, choices +from random import choice, choices, randint from .config.const import * @@ -148,20 +148,22 @@ commands = { "fortune": FORTUNE_REPLIES, "factcheck": FACTCHECK_REPLIES, "8ball": EIGHTBALL_REPLIES, - "roll": range(1, 10000), "coinflip": COINFLIP_HEADS_OR_TAILS, } -command_regex = re.compile("(\s|^)#(fortune|factcheck|8ball|roll|coinflip)", flags=re.A|re.I) +command_regex = re.compile("(\s|^)#(fortune|factcheck|8ball|roll([0-9]+)|coinflip)", flags=re.A|re.I) def command_regex_matcher(match, upper=False): if match.group(2) == 'coinflip' and random.random() < 0.01: result = COINFLIP_EDGE else: - result = str(choice(commands[match.group(2).lower()])) - if match.group(2) == 'roll': + if match.group(2).startswith('roll'): + max_num = int(match.group(3)) + result = randint(1, max_num) color = tuple(choices(range(256), k=3)) - result = f'Your roll: {result}' + result = f'Your roll (1-{max_num}): {result}' + else: + result = str(choice(commands[match.group(2).lower()])) return match.group(1) + result reason_regex_post = re.compile('(/post/[0-9]+)', flags=re.A) diff --git a/files/templates/formatting.html b/files/templates/formatting.html index 3783c3c0e..5b2079756 100644 --- a/files/templates/formatting.html +++ b/files/templates/formatting.html @@ -444,8 +444,8 @@ Roll - #roll - A number 1–9999. + #roll7 + A number 1–7. Coinflip