roll.py 584 B

123456789101112131415161718
  1. import dice
  2. from command_system import RollbotResponse, as_plugin
  3. @as_plugin
  4. def roll(db, message):
  5. argstr = message.raw_args
  6. try:
  7. rolls = []
  8. for roll_exp in argstr.split(","):
  9. roll = dice.roll(roll_exp)
  10. if not isinstance(roll, int):
  11. roll = int(roll)
  12. rolls.append(str(roll))
  13. return RollbotResponse(message, txt="Rolled {}, got: {}".format(argstr, ", ".join(rolls)))
  14. except Exception as _:
  15. return RollbotResponse(message, txt="Sorry - dice expression appears malformed. Add more ()'s")