Sha256: 1e58b87c11336c676fbe433f5365b6e5375c0da291acb3682d4fe198a5aca461
Contents?: true
Size: 948 Bytes
Versions: 1
Compression:
Stored size: 948 Bytes
Contents
require 'rest-client' module Lita module Handlers class OnewheelDuckDuckGo < Handler route /^duck\s+(.*)$/, :search, command: true route /^quack\s+(.*)$/, :search, command: true route /^ddg\s+(.*)$/, :search, command: true route /^fuck\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: ' if result['Abstract'].empty? reply += result['AbstractURL'] else reply += result['Abstract'][0..250] end Lita.logger.debug "Reply: #{reply}" response.reply reply end def get_result(query) JSON.parse(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.4 | lib/lita/handlers/onewheel_duckduckgo.rb |