My first Google Wave Robot: lobo-bot
Posted on · · Tags: google wave
Since I’m a bit too tired to do anything useful (or useless) in either Python or Java, and these are the only two languages Google support as of now, I decided to hit Github in search for a ruby wrapper to the wave api. On my first search I found Rave, a JRuby wrapper for (parts of) the python API.
First I downloaded and installed JRuby and Google App Engine SDK, which was surprisingly easy. I’ve never really had a chance to test any of them, so it was interesting seeing what they were all about.
Setting up a new Rave robot is a breeze too. After installing the gem, you use this command to set it all up:
jruby -S rave create [robot_name] [options]
So, on to the hard part; coming up with an idea that was good enough to implement. Well, I failed at that part, and created a robot that edits all blips, and reverses words wrapped with @’s. Extremely useless, but fun to watch. Here’s the robot.rb for lobo-bot:
require 'rubygems'
require 'rave'
module LoboBot
class Robot < Rave::Models::Robot
ME = "lobo-bot@appspot.com"
REGEXP = Regexp.compile '@\w+@'
def document_changed(event, context)
# Don't do anything if we triggered the event ourselves
return if event.modified_by == ME
context.blips.values.each do |blip|
blip.content.scan(REGEXP).each do |match|
# Find which range of the match
range = blip.content.rindex(match)..blip.content.rindex(match)+match.length
# Reverse!!
blip.set_text_in_range(range, match.reverse)
end
end
end
end
end
So… Well, it works, and I got to try out all of these new tools at once :-) For something a bit more useful, you can check out @senikk’s little robot who links all @names to their twitter accounts. I was thinking about porting it to Ruby, but unfortunately Rave doesn’t have set_annotation() method yet.
Hopefully I will come up with something more useful another day, but meanwhilst I recommend reading this stuff:
- Google Wave Robots: Overview
- Google Wave Robots: Python tutorial
- Google Wave Robots: Java tutorial
- And fork diminish7’s rave at GitHub!