Rbot Remote interface
Since [689] rbot exposes a drb (Distributed Ruby) interface for remote control. An example usage is given by the rbot-remote script in the bin/ directory, which feeds all the lines passed in as input to a specified channel or user.
To show the principles of the rbot drb interface, we will describe a small Ruby script which can be used as a svn post-commit-hook to force the update of the RSS feed watching the commits. This plugin requires the rbot to run with the rss and remotectl plugins enabled.
The first step is to create a DRbObject representing the bot. This is done via a line such as
rbot = DRbObject.new('drb://localhost:7268')
which assumes that the script is run from the same machine where the bot is located, and that the bot exposes its interface on the default port (7268). Of course real-life implementations should be more flexible.
The most important method of the remote rbot object is delegate(id, line).
The first parameter is a session ID. If nil, it means that the caller wants to act as an anonymous user. If it's not nil, then the id is associated with a previous login and the caller acts as the user it logged in as.
The second parameter is an actual command issued to the bot, and it's a Ruby String which is handled in a way similar to the way IRC messages are handled.
The return value of the delegate method is either false if the call failed (for example because the command was not recognized or the user was not allowed to issue that command) or a hash whose only key at the moment is :return and whose value is the return value of the command.
So the first thing to do is to login. This is done calling the remote login <user> <password> command, which returns the {{{id}} to be used in subsequent commands:
id = rbot.delegate("remote login rssuser rsspass")[:return]
where rssuser is a BotUser? which we created to handle these calls, and rsspass is its password.
Now that we have id, we can call the command we are interested in; we want to tell the rss plugin to reload a particular feed, but since the rss plugin does not expose any remote commands, we will have to use the dispatch command provided by the remoteclt plugin: this command simply takes its argument and feeds it back to the bot as if it was a private message issued on IRC. What we are looking for is thus:
rbot.delegate("dispatch rss rewatch somehandle")
where somehandle is the handle of the RSS feed we want to reload (the one watching the svn repository we just committed to).
Our rssreload.rb can thus be as simple as
#!/bin/ruby
rbot = DRbObject.new('drb://localhost:7268')
id = rbot.delegate("remote login rssuser rsspass")[:return]
rbot.delegate("dispatch rss rewatch somehandle")
