Jabbot

Official URL: github.com/badboy/jabbot/tree/master Jan-Erik Rediger (BadBoy_) (badboy.pytalhost.de)

Description

Jabbot is a Ruby microframework for creating Jabber/MUC bots, heavily inspired by Sinatra and Twibot. I modified the code of Twibot to fit my needs. The original Twibot code is located at: github.com/cjohansen/twibot/tree/master

A big thank you to Christian Johansen, who wrote the code for Twibot. Jabbot is heavily based on his code.

Usage

Simple example

require 'jabbot'

# Receive messages, and post them publicly
#
message do |message, params|
  post message.text
end

# Respond to query if they come from the right crowd
# post "message" => "user" is just some syntax sugar
# post "message", "user" will work to
query :from => [:cjno, :irbno] do |message, params|
  post "#{message.user} I agree" => message.user
end

# Listen in and log tweets
# (you can use "message :all" too ;)
message do |message, params|
  MyApp.log_message(message)
end

Running the bot

To run the bot, simply do:

ruby bot.rb

Configuration

Jabbot looks for a configuration file in ./config/bot.yml. It should contain atleast:

login: jabber_login
password: jabber_password
channel: channel_to_join
server: server_to_connect_to
nick: mybot

You can also configure with Ruby:

configure do |conf|
  conf.login = "my_account"
  conf.nick = "mybot"
do

If you don’t specify login and/or password in any of these ways, Jabbot will fail Nick is automatically set to “jabbot” unless something different is defined If you want you can set the Jabber Resource:

conf.resource ="mybot_resource"

Otherwise it is set to “jabbot”, too

“Routes”

Like Sinatra, and other web app frameworks, Jabbot supports “routes”: patterns to match incoming tweets and messages:

require 'jabbot'

message "time :country :city" do |message,params|
  time = MyTimeService.lookup(params[:country], params[:city])
  post "Time is #{time} in #{params[:city]}, #{params[:country]}"
end

You can have several “message” blocks (or “join”, “leave”, “query” or “subject”). Every matching block will be called.

Jabbot also supports regular expressions as routes:

require 'jabbot'

message /^time ([^\s]*) ([^\s]*)/ do |message, params|
  # params is an array of matches when using regexp routes
  time = MyTimeService.lookup(params[0], params[1])
  post "Time is #{time} in #{params[:city]}, #{params[:country]}"
end

Requirements

xmpp4r. You’ll need atleast 0.4. You can get it via rubygems:

gem install xmpp4r

or download it from: home.gna.org/xmpp4r/

Installation

gem sources -a http://gems.github.com  # you only have to do this once
gem install badboy-jabbot

Is it Ruby 1.9?

All tests passes even on Ruby 1.9. Seems like it works :)

Contributors

License

(The MIT License)

Copyright © 2009 Jan-Erik Rediger (Badboy_)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.