X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fdice.rb;h=7e0662b1d0f42a3dd5f96660fa51d6eec543f4ee;hb=7d2f6b2aa00632f55df231c72cec7661af8845f1;hp=230035ec419acf36b447b0bcb08bf326542d4d58;hpb=20badc14bb65e3f6d70ff7ecc6b4494e8bfbd12a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/dice.rb b/data/rbot/plugins/dice.rb index 230035ec..7e0662b1 100644 --- a/data/rbot/plugins/dice.rb +++ b/data/rbot/plugins/dice.rb @@ -53,7 +53,7 @@ class DicePlugin < Plugin dice = d.split(/d/) repr = [] r = 0 - unless dice[0] =~ /^[0-9]+/ + unless dice[0] =~ /^\d+/ dice[0] = 1 end for i in 0...dice[0].to_i @@ -86,28 +86,28 @@ class DicePlugin < Plugin def privmsg(m) # If either not given parameters or given incorrect parameters, return with # the help message - unless(m.params && m.params =~ /^[0-9]*d[0-9]+(\s*[+-]\s*([0-9]+|[0-9]*d[0-9])+)*$/) - m.nickreply "incorrect usage: " + help(m.plugin) + unless m.params && m.params =~ /^\d*d\d+(\s*[+-]\s*(\d+|\d*d\d)+)*$/ + m.reply "incorrect usage: " + help(m.plugin) return end # 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]+/) + a = m.params.gsub(/\s+/,'').scan(/^\d*d\d+|[+-]\d*d\d+|[+-]\d+/) # check nr of total dices and sides per dice nr = 0 a.each { |dice| dc, ds = dice.split(/d/) # check sides if ds.to_i > @bot.config['dice.max_sides'] - m.reply "sorry, don't have any dices with more than %u sides" % @bot.config['dice.max_sides'] + m.reply "sorry, don't have any dices with more than %u sides" % @bot.config['dice.max_sides'], :nick => true return end # We use .max with 1 so that specs such as d6 count as 1 and not as 0 nr += [dc.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'] + m.reply "can't handle more than %u dices" % @bot.config['dice.max_dices'], :nick => true return end @@ -123,7 +123,7 @@ class DicePlugin < Plugin t = t + tmp.get_view end t.chop! - m.nickreply r.to_s + " || " + m.params + ": " + t + m.reply(r.to_s + " || " + m.params + ": " + t, :nick => true) end end plugin = DicePlugin.new