Sha256: d86773931bec345ed39d7fb97e38075141c7e65c914077852ca01720109c2757

Contents?: true

Size: 939 Bytes

Versions: 1

Compression:

Stored size: 939 Bytes

Contents

module Lita
  module Handlers
    class ImgflipMemes < Handler
      Lita.register_handler(self)

      route /^(aliens)\s+(.+)/i, :make_meme, command: true,
        help: 'Aliens guy meme'

      def make_meme(message)
        template_id = 101470
        username = ENV.fetch('IMGFLIP_USERNAME', 'redacted')
        password = ENV.fetch('IMGFLIP_USERNAME', 'redacted')

        # generalize me
        # figure out when i might have multiple matches
        #   instead of just :first
        meme_name, text0, text1 = message.matches.first

        api_url = 'https://api.imgflip.com/caption_image'
        result = http.post api_url, {
          template_id: template_id,
          username: username,
          password: password,
          text0: text0,
          text1: text1
        }

        # clean me up
        image = JSON.parse(result.body).fetch("data").fetch("url")
        message.reply image
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-imgflip-memes-1.1.2 examples/001_make_meme.rb