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; N can be up to 6)".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") plugin.alias("dice","dndice") @plugin.command("flip") def flip(bot,channel,nick,*args): bot.say(channel,"{}: Coin lands {}".format(nick,RNG.choice(["Heads","Tails"])))