Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1.     @commands.command(aliases=['rtd'], description='usage: roll, roll 2, roll 8d12, roll 5d20+8')
  2.     async def roll(self, ctx, adxopb=None):
  3.         '''(rtd) Rolls dice in AdX+B notation. Default 1d6+0'''
  4.         adxopb = adxopb.lower()
  5.         op, b, opb = '', 0, ''
  6.  
  7.         if adxopb is None:
  8.             adx = adxopb = '1d6'
  9.         elif adxopb.isdigit():             # if no 'd':
  10.             adx = adxopb = f'{adxopb}d6'   #   default all d6
  11.         elif '+' in adxopb:
  12.             adx, op, b = adxopb.partition('+')
  13.             opb = f'{op}{b}'
  14.         elif '-' in adxopb:
  15.             adx, op, b = adxopb.partition('-')
  16.             opb = f'{op}{b}'
  17.         else:
  18.             adx = adxopb
  19.  
  20.         try:
  21.             a, x = map(int, adx.split('d'))             # extract numbers
  22.             rolls = [random.randrange(1, x+1) for die in range(a)]
  23.             total = self.ops[op](sum(rolls), int(b))    # sum of all rolls +/- b
  24.         except ValueError as e:
  25.             await ctx.send(f":interrobang: Invalid input: `{adxopb}`. Only `0-9 d + -` allowed.")
  26.         else:
  27.             rolls = ' '.join(list(map(str, rolls)))
  28.             output = f"🎲 **{total}**   |   *{ctx.author.display_name} rolled {adxopb.lower()}* ```x1\n{rolls} ({opb})```"
  29.             await ctx.message.delete()
  30.             await ctx.send(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement