Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. module Ruboty
  2. module Handlers
  3. class Ping < Base
  4. on(
  5. /(\d*)d(\d+) *(\+ *(\d+))?\z/i,
  6. name: "roll",
  7. description: "Roll dice"
  8. )
  9.  
  10. def roll(message)
  11. count = message.match_data[1].to_i
  12. count = 1 if count.zero?
  13.  
  14. surface = message.match_data[2].to_i
  15. additional = message.match_data[4]&.to_i
  16.  
  17. rolls = count.times.map { rand(surface) + 1}
  18. rolls << additional if additional
  19.  
  20. message.reply ":game_die: #{rolls.sum} (#{rolls.join(' + ')})"
  21. end
  22. end
  23. end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement