Class: RemoteModule

Inherits:
CoreBotModule
  • Object
show all
Includes:
RemoteCoreBotModule
Defined in:
lib/rbot/core/remote.rb

Instance Method Summary collapse

Constructor Details

#initializeRemoteModule

Returns a new instance of RemoteModule.



328
329
330
331
332
333
334
335
336
337
338
# File 'lib/rbot/core/remote.rb', line 328

def initialize
  super
  @port = @bot.config['remote.port']
  @host = @bot.config['remote.host']
  @drb = nil
  begin
    start_service if @bot.config['remote.autostart']
  rescue => e
    error "couldn't start remote service provider: #{e.inspect}"
  end
end

Instance Method Details

#cleanupObject



350
351
352
353
# File 'lib/rbot/core/remote.rb', line 350

def cleanup
  stop_service
  super
end

#handle_start(m, params) ⇒ Object



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/rbot/core/remote.rb', line 355

def handle_start(m, params)
  if @drb
    rep = "remote service provider already running"
    rep << " on port #{@port}" if m.private?
  else
    begin
      start_service(@port)
      rep = "remote service provider started"
      rep << " on port #{@port}" if m.private?
    rescue
      rep = "couldn't start remote service provider"
    end
  end
  m.reply rep
end

#remote_login(m, params) ⇒ Object



375
376
377
378
379
# File 'lib/rbot/core/remote.rb', line 375

def (m, params)
  id = @bot.auth.(params[:botuser], params[:password])
  raise "login failed" unless id
  return id
end

#remote_test(m, params) ⇒ Object



371
372
373
# File 'lib/rbot/core/remote.rb', line 371

def remote_test(m, params)
  @bot.say params[:channel], "This is a remote test"
end

#start_serviceObject



340
341
342
343
# File 'lib/rbot/core/remote.rb', line 340

def start_service
  raise "Remote service provider already running" if @drb
  @drb = DRb.start_service("druby://#{@host}:#{@port}", @bot.remote_object)
end

#stop_serviceObject



345
346
347
348
# File 'lib/rbot/core/remote.rb', line 345

def stop_service
  @drb.stop_service if @drb
  @drb = nil
end