Class: Lita::Handlers::OnewheelImages
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::OnewheelImages
- Defined in:
- lib/lita/handlers/onewheel_images.rb
Instance Method Summary collapse
Instance Method Details
#giphy(response) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lita/handlers/onewheel_images.rb', line 31 def giphy(response) unless config.giphy_enabled return end query = 'giphy ' + response.matches[0][0] result = ::OnewheelGoogle::search(query, config.custom_search_engine_id, config.google_api_key, config.safe_search, image = true) if result result['items'].each do |r| if r['mime'] == 'image/gif' if r['link'][/200_s.gif$/] r['link'].gsub! /200_s.gif/, 'giphy.gif' end Lita.logger.debug "response: #{r['link']}" response.reply r['link'] break end end end end |
#image(response) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lita/handlers/onewheel_images.rb', line 17 def image(response) query = response.matches[0][0] Lita.logger.debug("Config search prefix: #{config.search_prefix.empty?}") unless config.search_prefix.empty? Lita.logger.debug('Adding config prefix.') query = "#{config.search_prefix} #{query}" end Lita.logger.debug "query: #{query}" result = ::OnewheelGoogle::search(query, config.custom_search_engine_id, config.google_api_key, config.safe_search, image = true) Lita.logger.debug "response: #{result['items'][0]['link']}" response.reply result['items'][0]['link'] end |