Giter VIP home page Giter VIP logo

bototo's Introduction

Create Campfire bots

require 'bototo'

Bototo.setup do |config|
  config.bot_name       = 'mybot'
  config.subdomain      = 'mycompany'
  config.token          = 'campfire-api-token'
  config.room_name      = 'Main room'
  # config.handler_paths << File.dirname(__FILE__) + '/my_handlers' # load custom handlers from here
  # config.max_retries = 10 # default to -1, which means perform connection retries on drop forever.
end

Bototo.register do
  
  on 'foo' do |value|
    say "#{user.name}: pong #{value}"
  end
  
  on 'bar' do |value|
    say "Bar? What?"
  end
  
  on(/^exp (\d+) (\d+)?/) do |int1, int2|
    say "Expression is #{int1} - #{int2}"
  end
  
end

Bototo.run!

On campfire, on the "Main room" room:

mybot help

mybot image me a cute cat

Run examples/bot.rb

$ ruby examples/bot.rb

Custom handler classes

Bototo.register do ... end is fine for small command handlers. For anything more complicated you can create your own class extending from Bototo::Handlers::Base

class PrivateStatusHandler < Bototo::Handlers::Base
  
  URL = 'https://my.api.com/status'
  
  on "what's the status" do 
    get_json(URL) do |json|
      paste formatted(json)
    end
  end
  
  on /my bank account balance for (.+)/ do |date|
    # talk to your bank's API, or something
    say "My balance is ..."
  end
  
  protected
  
  def protected(json)
    # ... format json into nice string
    lines = json['reports'].map {|r| r['date'] + ' -- ' + r['description']}
    lines.join "\n"
  end
  
end

# Register your handler
Bototo.register PrivateStatusHandler

Daemonizing

You can daemonize with God or Monit, or using the Daemons gem:

require 'daemons'
require 'bototo'

# ... config

Bototo.register do

   # your commands here
   
end

# Run daemonized

Daemons.run_proc('my_bot') do
   Bototo.run!
end

Now you can control with

$ ruby a_bot.rb start|stop|run|restart

bototo's People

Contributors

ismasan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.