loo.no

Home, sweet home

My first Google Wave Robot: lobo-bot

29. July 2009

I decided to sit down and try to make my own little useless Google Wave robot tonight, and check out the current state of Ruby on 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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:


7f31a917f23afac4b3a7a9482ae87843

diminish7 commented about 21 hours later (July 30, 2009 17:12)

Hey Lars, good to see someone other than me using Rave :-) Let me know if you have any feedback!

70010d8579dc2944c64d00c8e1480d7a

Daniel commented 5 days later (August 04, 2009 15:50)

Hi,
It seems quite a fast libary to start to use. Thanks for sharing.

/Daniel

C526763440ed22dcc3d6e3548ab34eca

unlimited commented 2 months later (October 18, 2009 02:01)

Hei, har noen her har en invitasjon til å dele? Det ville bli verdsatt! Takk!


Write a comment