Class: Muzang::Plugins::Eval
- Inherits:
-
Object
- Object
- Muzang::Plugins::Eval
- Includes:
- Helpers
- Defined in:
- lib/muzang-plugins/muzang-eval.rb
Instance Method Summary collapse
- #call(connection, message) ⇒ Object
-
#initialize(bot) ⇒ Eval
constructor
A new instance of Eval.
- #safe(*args, &block) ⇒ Object
Methods included from Helpers
#create_database, #match, #on_channel, #on_join
Constructor Details
#initialize(bot) ⇒ Eval
Returns a new instance of Eval.
25 26 27 |
# File 'lib/muzang-plugins/muzang-eval.rb', line 25 def initialize(bot) @bot = bot end |
Instance Method Details
#call(connection, message) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/muzang-plugins/muzang-eval.rb', line 29 def call(connection, ) on_channel() do match(, /^\% (.*)/) do |match| operation = proc do safe(match[1]) end callback = proc do |tuple| result, error = tuple connection.msg(.channel, "#{result}") if result connection.msg(.channel, "Error: #{error}") if error end EM.defer(operation, callback) end end end |
#safe(*args, &block) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/muzang-plugins/muzang-eval.rb', line 45 def safe(*args, &block) unless args.first =~ /EM|EventMachine/ @safe ||= Safe.new @safe.safe(*args, &block) end end |