import time,random from sibyl.lib.decorators import botcmd,botinit @botinit def init(bot): random.seed(time.time()) @botcmd def roll(bot,mess,args): """rolls n s-sided dice - roll (n)d(s)""" # Evaluate each type of dice for n in args: numdice = int(n.split("d")[0] or '1') dice = n.split("d")[1] # Check for additive modifier if "+" in dice: mod = int(dice.split("+")[1]) dice = int(dice.split("+")[0]) else: mod = 0 dice = int(dice) # Instantiate rolls rolls = [] # Generate rolls for i in range(numdice, 0, -1): rolls.insert(0,random.randint(1,dice)) # Prepare results results = n + ": " for roll in rolls: results = results + " " + str(roll) if mod: results += " = %s +%s" % (sum(rolls),mod) results += " = " + str(sum(rolls)+mod) bot.send(results,mess.get_from())