forked from rDrama/rDrama
allow ppl to choose the size of roll
parent
7bd6ebef8a
commit
e200efba6e
|
@ -1,6 +1,6 @@
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from random import choice, choices
|
from random import choice, choices, randint
|
||||||
|
|
||||||
from .config.const import *
|
from .config.const import *
|
||||||
|
|
||||||
|
@ -148,20 +148,22 @@ commands = {
|
||||||
"fortune": FORTUNE_REPLIES,
|
"fortune": FORTUNE_REPLIES,
|
||||||
"factcheck": FACTCHECK_REPLIES,
|
"factcheck": FACTCHECK_REPLIES,
|
||||||
"8ball": EIGHTBALL_REPLIES,
|
"8ball": EIGHTBALL_REPLIES,
|
||||||
"roll": range(1, 10000),
|
|
||||||
"coinflip": COINFLIP_HEADS_OR_TAILS,
|
"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):
|
def command_regex_matcher(match, upper=False):
|
||||||
if match.group(2) == 'coinflip' and random.random() < 0.01:
|
if match.group(2) == 'coinflip' and random.random() < 0.01:
|
||||||
result = COINFLIP_EDGE
|
result = COINFLIP_EDGE
|
||||||
else:
|
else:
|
||||||
result = str(choice(commands[match.group(2).lower()]))
|
if match.group(2).startswith('roll'):
|
||||||
if match.group(2) == 'roll':
|
max_num = int(match.group(3))
|
||||||
|
result = randint(1, max_num)
|
||||||
color = tuple(choices(range(256), k=3))
|
color = tuple(choices(range(256), k=3))
|
||||||
result = f'<b style="color:rgb{color}">Your roll: {result}</b>'
|
result = f'<b style="color:rgb{color}">Your roll (1-{max_num}): {result}</b>'
|
||||||
|
else:
|
||||||
|
result = str(choice(commands[match.group(2).lower()]))
|
||||||
return match.group(1) + result
|
return match.group(1) + result
|
||||||
|
|
||||||
reason_regex_post = re.compile('(/post/[0-9]+)', flags=re.A)
|
reason_regex_post = re.compile('(/post/[0-9]+)', flags=re.A)
|
||||||
|
|
|
@ -444,8 +444,8 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Roll</td>
|
<td>Roll</td>
|
||||||
<td>#roll</td>
|
<td>#roll7</td>
|
||||||
<td>A number 1–9999.</td>
|
<td>A number 1–7.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Coinflip</td>
|
<td>Coinflip</td>
|
||||||
|
|
Loading…
Reference in New Issue