Sha256: b4208c09f666e08eede0562a785bea5083e72a0e32bced038839c18ec92a392a
Contents?: true
Size: 905 Bytes
Versions: 4
Compression:
Stored size: 905 Bytes
Contents
plugin = Plugin.new "math" # flips a coin which can come up heads or tails plugin.handle(/^pi$/i) do |data| next data[:room].say "\u{03C0} = #{Math::PI}" end plugin.handle(/^calc$/i) do |data, args| args_string = args.join(' ') args_string.gsub!(/log/, "\000") args_string.gsub!(/sqrt/, "\001") args_string.gsub!(/\^/, "**") args_string.gsub!(/,/, ".") if not args_string.match(/^[ 0-9+*\/\.()\-\000\001]+$/) next data[:room].say "Could not parse string." end begin result = Kernel.eval(args_string) rescue Exception => e next data[:room].say "#{e.to_s}" end if result.nil? next data[:room].say "undef" elsif result == 42 next data[:room].say "the Answer to the Ultimate Question of Life, The Universe, and Everything" else next data[:room].say result.to_s end end $bot.plugins.add(plugin)
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
fantasy-irc-0.3.0 | lib/plugins/math.rb |
fantasy-irc-0.2.3 | lib/plugins/math.rb |
fantasy-irc-0.2.2 | lib/plugins/math.rb |
fantasy-irc-0.2.1 | lib/plugins/math.rb |