class Ruboty::Handlers::Responder

Public Instance Methods

respond(message) click to toggle source
# File lib/ruboty/handlers/responder.rb, line 11
def respond(message)
  response = get_response(message)
  message.reply(response) unless response.nil?
end

Private Instance Methods

get_response(message) click to toggle source
# File lib/ruboty/handlers/responder.rb, line 18
def get_response(message)
  #NOTE: only use the last keyword matched
  list = response_list(message)

  unless list.empty?
    response = list[list.to_a.last[0]]
    response[response.keys.sample]
  end
end
json_path() click to toggle source
# File lib/ruboty/handlers/responder.rb, line 36
def json_path
  '/keywords/responses.json'
end
keyword_list() click to toggle source
# File lib/ruboty/handlers/responder.rb, line 32
def keyword_list
  @keyword_list ||= JSON.parse(File.read(File.join(File.dirname(File.expand_path('..', __FILE__)), json_path)))
end
response_list(message) click to toggle source
# File lib/ruboty/handlers/responder.rb, line 28
def response_list(message)
  keyword_list.select { |key, value| message[:sentence].match(key.to_s) }
end