Rubot is a framework for creating IRC bots.
gem install rubot
rubot new botname
cd botname
bundle install
vim config.yml
bundle exec rubot server
nohup bundle exec rubot server &
Rubot::Controller
adds functionality to the class, namely the
message
method. message
is an instance of the message that matched a
listener or triggered a command.
You can get the message sender's nick from message.from
class WebLinkController < Rubot::Controller
command :calc do
reply Google.calc(:q => message.text)
end
command :google, :g do
reply Google.lmgtfy_url_for(message.text)
end
end
class SubstitutionsController < Rubot::Controller
listener :matches => /hello/ do
reply "hello, #{message.from}"
end
end
A resource is just a class or module that is a source of data. Resources are looked for
in APP_ROOT/resources
module Google
def self.lmgtfy_url_for(query)
"http://www.lmgtfy.com/?q=#{CGI.escape(query)}"
end
end
Rubot ships with a Rubot::WebResource
class that can be subclassed to add simple
web scraping functionality.
class Google < Rubot::WebResource
get :calc, "http://www.google.com/search" do |doc|
doc.css(".r")[0].text
end
end
rake db:migration migration_name
rake db:migrate
NOTE: both the migrations and the sqlite database itself are stored
within APP_ROOT/db
class Fact < Sequel::Model
def self.random
# this is a pretty shitty way of getting a random record
DB["select * from facts order by random() limit 1"].first
end
end
now Fact.random
can be used from a controller
- provides a very simple DSL for quickly adding commands
- can update the application via git and reload
- incorporate some resources, commands, listeners as core configurable extensions/plugins?
Chris Thorn (@thorncp)
Matt Culpepper (@mculp)