Sha256: 09ee041f9ce2890caa5be1a62f264a7f9bfef8e2778fda154be8642bdcce36eb

Contents?: true

Size: 669 Bytes

Versions: 1

Compression:

Stored size: 669 Bytes

Contents

require 'rest-client'

module Lita
  module Handlers
    class OnewheelDuckDuckGo < Handler
      route /^duck\s+(.*)$/, :search, command: true

      def search(response)
        query = response.matches[0][0]
        Lita.logger.debug "Querying for #{query}"
        result = get_result(query)
        Lita.logger.debug "Result: #{result}"
        reply = "DuckDuckGo Result: #{result['Abstract'][0..250]}"
        Lita.logger.debug "Reply: #{reply}"
        response.reply reply
      end

      def get_result(query)
        result = RestClient.get("http://api.duckduckgo.com/?q=#{query}&format=json")
      end

      Lita.register_handler(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-onewheel-duckduckgo-0.0.0 lib/lita/handlers/onewheel_duckduckgo.rb