Add DND dice func
This commit is contained in:
parent
9dd3680825
commit
f65dbf934c
|
@ -0,0 +1,24 @@
|
|||
import plugin, re, random, traceback
|
||||
|
||||
DICE = re.compile("(\d)d(\d+)([+-]\d+)?")
|
||||
RNG = random.SystemRandom()
|
||||
|
||||
@plugin.command("dndice","{NdS{+|-}MOD|NdS}")
|
||||
def dndice(bot,channel,nick,roll,*args):
|
||||
# print("dndice {}".format(roll))
|
||||
# try:
|
||||
m = DICE.match(roll)
|
||||
if m is None:
|
||||
bot.say(channel,"{}: Please input a roll in the form of NdS{+|-}MOD or simply NdS. (1d20+5 or 1d6)".format(nick))
|
||||
return
|
||||
num, sides, mod = m.groups()
|
||||
num, sides = int(num), int(sides)
|
||||
results = [RNG.randint(1,sides) for x in range(num)]
|
||||
if mod==None:
|
||||
bot.say(channel,"{}: Result: {} {}".format(nick,sum(results),"("+", ".join([str(res) for res in results])+")" if len(results)>1 else "").rstrip())
|
||||
else:
|
||||
mod = int(mod)
|
||||
bot.say(channel,"{}: Result: {} ({}{:+})".format(nick,sum(results)+mod,"("+", ".join([str(res) for res in results])+")" if len(results)>1 else results[0],mod))
|
||||
# except Exception:
|
||||
# traceback.print_exc()
|
||||
# raise Exception("minerobber check the logs")
|
Loading…
Reference in New Issue