Sha256: 27eb6a8b6526d915574a667944126fa812df218a288db87eb1b50da8f96de5a9

Contents?: true

Size: 635 Bytes

Versions: 1

Compression:

Stored size: 635 Bytes

Contents

require "lita"
require 'open-uri'
require 'nokogiri'

module Lita
  module Handlers
    class RedditImagePreview < Handler

      route %r{https://www.reddit.com/r/}i, :reddit_image_preview, command: true

      def reddit_image_preview(response)
        html = open(response.args[0], 'User-Agent' => 'lita')
        # puts html.read
        doc = Nokogiri::HTML(html.read)
        if doc.css('img.media-element')[0]
          # puts doc.css('img.media-element')[0].attr('src')
          response.reply doc.css('img.media-element')[0].attr('src')
        end
      end

    end

    Lita.register_handler(RedditImagePreview)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-reddit-image-preview-1.0.2 lib/lita/handlers/reddit_image_preview.rb