brettstimmerman / jabber-bot

Easily create simple regex powered Jabber bots.
BSD 3-Clause "New" or "Revised" License
91 stars 30 forks source link

= Jabber::Bot

Easily create simple regex powered Jabber bots.

Jabber::Bot makes it simple to create and command your own Jabber bot. Bots are created by defining commands powered by regular expressions and Ruby.

Author:: Brett Stimmerman (mailto:brettstimmerman@gmail.com) Version:: 1.3.0 (2011-05-15) Copyright:: Copyright (c) 2011 Brett Stimmerman. All rights reserved. License:: New BSD License (http://opensource.org/licenses/bsd-license.php) Website:: http://github.com/brettstimmerman/jabber-bot

== Requires

== Usage

require 'rubygems' require 'jabber/bot'

Create a public Jabber::Bot

config = { :name => 'SampleBot', :jabber_id => 'bot@example.com', :password => 'secret', :master => 'master@example.com', :is_public => true }

bot = Jabber::Bot.new(config)

Give your bot a private command, 'rand'

bot.add_command( :syntax => 'rand', :description => 'Produce a random number from 0 to 10', :regex => /^rand$/ ) { rand(10).to_s }

Give your bot a public command, 'puts ' with an alias 'p '

bot.add_command( :syntax => 'puts ', :description => 'Write something to $stdout', :regex => /^puts\s+(.+)$/, :alias => [ :syntax => 'p ', :regex => /^p\s+(.+)$/ ], :is_public => true ) do |sender, message| puts "#{sender} says '#{message}'" "'#{message}' written to $stdout" end

Bring your new bot to life

bot.connect