Skip to content

Instantly share code, notes, and snippets.

@davecowart
Created October 24, 2011 15:12
Show Gist options
  • Save davecowart/1309282 to your computer and use it in GitHub Desktop.
Save davecowart/1309282 to your computer and use it in GitHub Desktop.
on :channel, /^#{self.nick} roll (\d*)d(\d+)($|[\+\-]\d+$)/ do |m, n, d, mod|
total = 0;
dice = n.to_i == 0 ? 1 : [n.to_i.abs, 10].min
dice.times do
result = (Random.new).rand(1..d.to_i.abs)
m.reply "#{m.user.nick} rolls a #{result}"
total += result
end
unless mod.to_i == 0
m.reply "Adding #{mod}"
total += mod.to_i
end
m.reply "Total: #{total}" if dice > 1 || mod.to_i != 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment