Coder Social home page Coder Social logo

rubot's Introduction

Rubot is a framework for creating IRC bots.

Installation

gem install rubot
rubot new botname
cd botname
bundle install 
vim config.yml
bundle exec rubot server
nohup bundle exec rubot server & 

Usage

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

adding a command

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

using listeners

class SubstitutionsController < Rubot::Controller
  listener :matches => /hello/ do
    reply "hello, #{message.from}"
  end
end

adding resources

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

using Rubot::WebResource

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

generate a migration

rake db:migration migration_name

migrate the database

rake db:migrate

NOTE: both the migrations and the sqlite database itself are stored within APP_ROOT/db

use database in a resource

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

why should I use rubot to build my IRC bot?

  1. provides a very simple DSL for quickly adding commands
  2. can update the application via git and reload

Future

  • incorporate some resources, commands, listeners as core configurable extensions/plugins?

Authors

Chris Thorn (@thorncp)

Matt Culpepper (@mculp)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.