Skip to content
Browse files

Apply limits to dice

  • Loading branch information...
1 parent 128789f commit 0dc615e83f4cf0d910011ac8b73630851bb45511 @raggi committed Nov 13, 2009
Showing with 7 additions and 3 deletions.
  1. +7 −3 examples/dice.bot
View
10 examples/dice.bot
@@ -4,10 +4,14 @@ class Dice
return if sender['name'] == 'bot'
case content
when /(\d+)[dD](\d+)(?:\+(\d+))?/
- results = Array.new($1.to_i){ 1+rand($2.to_i) }
+ dice, faces, bonus = $1.to_i, $2.to_i, $3
+ if dice >= 1000 || faces >= 10000
+ return client.send_message("#{dice}d#{faces} is too large")
+ end
+ results = Array.new(dice){ 1+rand(faces) }
total = results.inject { |t,v| t + v }
- total += $3.to_i if $3
- client.send_message "#{total} from #{results.inspect} #{"+#{$3}" if $3}"
+ total += bonus.to_i if bonus
+ client.send_message "#{total} from #{results.inspect} #{"+#{bonus}" if bonus}"
end
end
end

0 comments on commit 0dc615e

Please sign in to comment.
Something went wrong with that request. Please try again.