Sha256: db909867063958097e87472c1dcd425198c19a38661b17629c4484d6b9e0cf3f

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

require 'robut/plugin'
require 'robut/plugin/giphy/base'
require 'net/http'
require 'json'

class Robut::Plugin::Giphy::Meme
  include Robut::Plugin
  include Robut::Plugin::Giphy::Base

  desc "giphy <subject>; <line_1> [; <line_2>] - searches for and displays a gif matching <subject> from giphy, with meme text line_1 and line_2 overlaid"
  match /^giphy ([^;]+);(.*)$/, :sent_to_me => true do |gif, text|
    begin
      uri = giphy_uri(gif)
      if uri
        lines = text.split(';').map {|t| t.strip}
        meme = "http://v1.memecaptain.com/i?u=#{uri}&tt=#{CGI.escape(lines[0])}"
        meme += "&tb=#{CGI.escape(lines[1])}" if lines.count == 2

        if lines.count < 3
          reply("#{meme}\nPowered by Giphy and MemeCaptain")
        else
          reply("That's too much text. Don't be greedy.")
        end
      else
        reply("Sorry, I couldn't find a gif for that.")
      end
    rescue
      reply('Giphy returned an error')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
robut-giphy-0.1.0 lib/robut/plugin/giphy/meme.rb