semicolon support. multiple rolls on one line, separated by ;
This commit is contained in:
parent
ec2be10aca
commit
9f6ae529fe
107
dr.botzo.py
107
dr.botzo.py
@ -189,67 +189,70 @@ def sub_countdown(connection, event, nick, userhost, replypath, what, admin_unlo
|
||||
#####
|
||||
|
||||
def sub_dice(connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||
pattern = '^(?:(\d+)#)?(?:(\d+)/)?(\d+)?d(\d+)(?:(\+|\-)(\d+))?(?:\s+(.*))?'
|
||||
regex = re.compile(pattern)
|
||||
roll = what
|
||||
matches = regex.search(roll)
|
||||
overallroll = what
|
||||
|
||||
if matches is not None:
|
||||
# set variables including defaults for unspecified stuff
|
||||
faces = int(matches.group(4))
|
||||
comment = matches.group(7)
|
||||
rolls = re.split(';\s*', overallroll)
|
||||
for roll in rolls:
|
||||
pattern = '^(?:(\d+)#)?(?:(\d+)/)?(\d+)?d(\d+)(?:(\+|\-)(\d+))?(?:\s+(.*))?'
|
||||
regex = re.compile(pattern)
|
||||
matches = regex.search(roll)
|
||||
|
||||
if matches.group(1) is None:
|
||||
times = 1
|
||||
else:
|
||||
times = int(matches.group(1))
|
||||
if matches is not None:
|
||||
# set variables including defaults for unspecified stuff
|
||||
faces = int(matches.group(4))
|
||||
comment = matches.group(7)
|
||||
|
||||
if matches.group(3) is None:
|
||||
dice = 1
|
||||
else:
|
||||
dice = int(matches.group(3))
|
||||
|
||||
if matches.group(2) is None:
|
||||
top = dice
|
||||
else:
|
||||
top = int(matches.group(2))
|
||||
|
||||
if matches.group(5) is None or matches.group(6) is None:
|
||||
modifier = 0
|
||||
else:
|
||||
if str(matches.group(5)) == '-':
|
||||
modifier = -1 * int(matches.group(6))
|
||||
if matches.group(1) is None:
|
||||
times = 1
|
||||
else:
|
||||
modifier = int(matches.group(6))
|
||||
times = int(matches.group(1))
|
||||
|
||||
result = ''
|
||||
if comment is not None:
|
||||
result += comment + ': '
|
||||
if matches.group(3) is None:
|
||||
dice = 1
|
||||
else:
|
||||
dice = int(matches.group(3))
|
||||
|
||||
for t in range(times):
|
||||
ressubstr = ""
|
||||
rolls = []
|
||||
for d in range(dice):
|
||||
rolls.append(str(random.randint(1, faces)))
|
||||
rolls.sort()
|
||||
rolls.reverse()
|
||||
ressubstr = ','.join(rolls[0:top])
|
||||
sum = 0
|
||||
for r in rolls[0:top]:
|
||||
sum += int(r)
|
||||
sumplus = sum + modifier
|
||||
result += str(sumplus) + ' [' + ressubstr
|
||||
if modifier != 0:
|
||||
if modifier > 0:
|
||||
result += ' + ' + str(modifier)
|
||||
if matches.group(2) is None:
|
||||
top = dice
|
||||
else:
|
||||
top = int(matches.group(2))
|
||||
|
||||
if matches.group(5) is None or matches.group(6) is None:
|
||||
modifier = 0
|
||||
else:
|
||||
if str(matches.group(5)) == '-':
|
||||
modifier = -1 * int(matches.group(6))
|
||||
else:
|
||||
result += ' - ' + str(-1 * modifier)
|
||||
result += ']'
|
||||
modifier = int(matches.group(6))
|
||||
|
||||
if t != times-1:
|
||||
result += ', '
|
||||
result = ''
|
||||
if comment is not None:
|
||||
result += comment + ': '
|
||||
|
||||
connection.privmsg(replypath, result)
|
||||
for t in range(times):
|
||||
ressubstr = ""
|
||||
rolls = []
|
||||
for d in range(dice):
|
||||
rolls.append(str(random.randint(1, faces)))
|
||||
rolls.sort()
|
||||
rolls.reverse()
|
||||
ressubstr = ','.join(rolls[0:top])
|
||||
sum = 0
|
||||
for r in rolls[0:top]:
|
||||
sum += int(r)
|
||||
sumplus = sum + modifier
|
||||
result += str(sumplus) + ' [' + ressubstr
|
||||
if modifier != 0:
|
||||
if modifier > 0:
|
||||
result += ' + ' + str(modifier)
|
||||
else:
|
||||
result += ' - ' + str(-1 * modifier)
|
||||
result += ']'
|
||||
|
||||
if t != times-1:
|
||||
result += ', '
|
||||
|
||||
connection.privmsg(replypath, result)
|
||||
|
||||
#####
|
||||
# on_connect
|
||||
|
Loading…
Reference in New Issue
Block a user