- a = m.params.scan(/^[0-9]*d[0-9]+|[+-][0-9]*d[0-9]+|[+-][0-9]+/)
- r = rolldice(a[0])
- t = "[" + a[0].to_s + "=" + r.to_s + "] "
+
+ # Extract the actual dice request from the message parameters, splitting it
+ # into dice and modifiers
+ a = m.params.gsub(/\s+/,'').scan(/^[0-9]*d[0-9]+|[+-][0-9]*d[0-9]+|[+-][0-9]+/)
+ # check nr of total dices
+ nr = 0
+ a.each { |dice|
+ # We use .max with 1 so that specs such as d6 count as 1 and not as 0
+ nr += [dice.split(/d/)[0].to_i, 1].max
+ }
+ if nr > @bot.config['dice.max_dices']
+ m.reply "can't handle more than %u dices" % @bot.config['dice.max_dices']
+ return
+ end
+
+ # Roll the dice with the extracted request
+ rolled = rolldice(a[0])
+ r = rolled.total
+ t = rolled.get_view()
+
+ # Deal with all the remaining parts of the given dice request