X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fmath.rb;h=9dd35c985fabdb2f53be5e942b1a4644aab6a4f5;hb=7a128ab6457c9b79ed31a5562be98e1718bfaf80;hp=afa4737cd9eff71bf10292245ea04e67c8a8b132;hpb=10880d600dd3ae7acf3144ef1ab0c9bd329492e2;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/math.rb b/data/rbot/plugins/math.rb index afa4737c..9dd35c98 100644 --- a/data/rbot/plugins/math.rb +++ b/data/rbot/plugins/math.rb @@ -80,19 +80,20 @@ class MathPlugin < Plugin expr.gsub!(/\bover /, "/ ") expr.gsub!(/\bsquared/, "**2 ") expr.gsub!(/\bcubed/, "**3 ") - expr.gsub!(/\bto\s+(\d+)(r?st|nd|rd|th)?( power)?/, "**\1 ") + expr.gsub!(/\bto\s+(\d+)(r?st|nd|rd|th)?( power)?/, '**\1 ') expr.gsub!(/\bpercent of/, "*0.01*") expr.gsub!(/\bpercent/, "*0.01") expr.gsub!(/\% of\b/, "*0.01*") expr.gsub!(/\%/, "*0.01") - expr.gsub!(/\bsquare root of (\d+)/, "\1 ** 0.5 ") - expr.gsub!(/\bcubed? root of (\d+)/, "\1 **(1.0/3.0) ") + expr.gsub!(/\bsquare root of (\d+(\.\d+)?)/, '\1 ** 0.5 ') + expr.gsub!(/\bcubed? root of (\d+(\.\d+)?)/, '\1 **(1.0/3.0) ') expr.gsub!(/ of /, " * ") expr.gsub!(/(bit(-| )?)?xor(\'?e?d( with))?/, "^") expr.gsub!(/(bit(-| )?)?or(\'?e?d( with))?/, "|") expr.gsub!(/bit(-| )?and(\'?e?d( with))?/, "& ") expr.gsub!(/(plus|and)/, "+") + debug expr if (expr =~ /^\s*[-\d*+\s()\/^\.\|\&\*\!]+\s*$/ && expr !~ /^\s*\(?\d+\.?\d*\)?\s*$/ && expr !~ /^\s*$/ && @@ -109,9 +110,9 @@ class MathPlugin < Plugin answer = "a number with >30 digits..." end end - m.reply answer + m.reply answer.to_s rescue Exception => e - error "couldn't evaluate expression \"#{m.params}\": #{e.inspect}" + error e m.reply "illegal expression \"#{m.params}\"" return end