Sha256: 455cf514962438f9ab6cfac1f2e81af47e687dbe6a4ad443d823d52c9cf6d08b

Contents?: true

Size: 756 Bytes

Versions: 1

Compression:

Stored size: 756 Bytes

Contents

# from lita-imgflip-memes/lib/lita/handlers/imgflip_memes.rb
TEMPLATES = [
  { template_id: 101470, pattern: /^aliens()\s+(.+)/i,
    help: 'Ancient aliens guy' },
  { template_id: 61579, pattern: /(one does not simply) (.+)/i,
    help: 'one does not simply walk into mordor' },
]

TEMPLATES.each do |t|
  route t.fetch(:pattern), :make_meme, command: true, help: t.fetch(:help)
end

def make_meme(message)
  match = message.matches.first
  raise ArgumentError unless match.size == 2
  line1, line2 = match

  templates = TEMPLATES.select do |t|
    t.fetch(:pattern) == message.pattern
  end
  template = templates.first

  raise ArgumentError if template.nil?

  image = pull_image(template.fetch(:template_id), line1, line2)

  message.reply image
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-imgflip-memes-1.1.2 examples/005_add_templates.rb