| Class | ::Bot::RemoteObject |
| In: |
lib/rbot/core/remote.rb
|
| Parent: | Object |
The Irc::Bot::RemoteObject class represents and object that will take care of interfacing with remote clients
Example client session:
require 'drb'
rbot = DRbObject.new_with_uri('druby://localhost:7268')
id = rbot.delegate(nil, 'remote login someuser somepass')[:return]
rbot.delegate(id, 'some secret command')
Of course, the remote login is only neede for commands which may not be available to everyone
Initialization is simple
# File lib/rbot/core/remote.rb, line 213
213: def initialize(bot)
214: @bot = bot
215: end
The delegate method. This is the main method used by remote clients to send commands to the bot. Most of the time, the method will be called with only two parameters (session id and a String), but we allow more parameters for future expansions.
The session_id can be nil, meaning that the remote client wants to work as an anoynomus botuser.
# File lib/rbot/core/remote.rb, line 225
225: def delegate(session_id, *pars)
226: warn "Ignoring extra parameters" if pars.length > 1
227: cmd = pars.first
228: client = @bot.auth.remote_user(session_id)
229: raise "No such session id #{session_id}" unless client
230: debug "Trying to dispatch command #{cmd.inspect} from #{client.inspect} authorized by #{session_id.inspect}"
231: m = RemoteMessage.new(@bot, client, cmd)
232: @bot.remote_dispatcher.handle(m)
233: end