Sha256: 3140e421c30b5caf594fbe20985a591e1f756527b0fcdaf3d6545dd40382452b
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
module Muzang module Plugins class Safe def safe(code, sandbox=nil) error = nil begin $-w = nil @sandbox ||= Object.new yield(@sandbox) if block_given? $SAFE = 3 result = eval(code, @sandbox.send(:binding)) rescue Exception => error error = error end return result, error end end class Eval include Muzang::Plugins::Helpers def initialize(bot) @bot = bot end def call(connection, message) on_channel(message) do match(message, /^\% (.*)/) do |match| operation = proc do safe(match[1]) end callback = proc do |tuple| result, error = tuple connection.msg(message.channel, "#{result}") if result connection.msg(message.channel, "Error: #{error}") if error end EM.defer(operation, callback) end end end def safe(*args, &block) unless args.first =~ /EM|EventMachine/ @safe ||= Safe.new @safe.safe(*args, &block) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
muzang-plugins-1.1.6 | lib/muzang-plugins/muzang-eval.rb |