class Chatterbot::Bot

primary Bot object, includes all the other modules

Constants

HANDLER_CALLS

handlers that can use the REST API

Public Class Methods

new(params={}) click to toggle source

Create a new bot. No options for now.

# File lib/chatterbot/bot.rb, line 30
def initialize(params={})
  if params.has_key?(:name)
    @botname = params.delete(:name)
  end

  @config = load_config(params)
  @run_count = 0

  #
  # check for command line options
  # handle resets, etc
  #

  at_exit do
    if !@handlers.empty? && @run_count <= 0 && skip_run? != true
      run!
    end
    
    raise $! if $!
  end
  @handlers = {}
end

Public Instance Methods

after_run() click to toggle source
# File lib/chatterbot/bot.rb, line 79
def after_run

end
before_run() click to toggle source
# File lib/chatterbot/bot.rb, line 75
def before_run
  @run_count = @run_count + 1
end
call_api_immediately?() click to toggle source
# File lib/chatterbot/bot.rb, line 83
def call_api_immediately?
  true
end
register_handler(method, opts = nil, &block) click to toggle source
# File lib/chatterbot/bot.rb, line 87
def register_handler(method, opts = nil, &block)
  # @todo raise error if method already defined
  @handlers[method] = Handler.new(opts, &block)

  h = @handlers[method]
  self.send(method, *(h.opts)) do |obj|
    h.call(obj)
  end
end
run!() click to toggle source

run the bot with the REST API

# File lib/chatterbot/bot.rb, line 60
def run!
  before_run

  HANDLER_CALLS.each { |c|
    if (h = @handlers[c])
      send(c, *(h.opts)) do |obj|
        h.call(obj)
      end
    end
  }

  after_run
end
screen_name() click to toggle source
# File lib/chatterbot/bot.rb, line 53
def screen_name
  @screen_name ||= client.settings.screen_name
end