lita-imgflip-memes 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1bb029dfb75f302b33b7f55b85f625def044860
4
- data.tar.gz: e82ea6c2d832a59824d24b958f5f50575d3b5980
3
+ metadata.gz: 61806a949d88cdd70342fc2f2991494b1411fee0
4
+ data.tar.gz: 8897c43080275c3b72c5b0abb01267668fe2792c
5
5
  SHA512:
6
- metadata.gz: 522ea81eaf4c6a9ebe2a9df08803907cfbba59bb51ae62e66cb1d301d3dc24303e1c6b4c9180624c9e75a905ea0d52675a9554ad45469ce618ed7550c6ecd397
7
- data.tar.gz: 540c81fe39be7571ca53d0a181f03716b2b9512caf6dbf705a99ca17a9561738246f5791247a26aa2f0e6fc5f490fcfa25b2e986b28f290f5658af3eba0e6ebb
6
+ metadata.gz: acc6ecfef1d344bf24ddb2242466398e552dd03b67aa156138d7f0ec4e4fd9967e3d4d74960b8ac45906eccca969f52e761607e704927f5efa618a18e6f6ccf6
7
+ data.tar.gz: 6fa2d4a56645b08a1bedc17a551cbebad59c7dacca0d9eed71ecb9333530671324d0e4ce502134e12ccd8f8ad98f6f1ed26c9ed293befbe0709091e465067ffe
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.3.1
4
4
  script: bundle exec rake
5
5
  before_install:
6
6
  - gem update --system
data/README.md CHANGED
@@ -30,6 +30,18 @@ I have set up this gem to deafult to the following environment variables if the
30
30
  ENV['IMGFLIP_API_PASSWORD']
31
31
  ```
32
32
 
33
+ ### Adding new memes to your local Lita bot
34
+ On a suggestion from [@joshwlewis](https://github.com/joshwlewis) I've added a way to put new memes in your Lita bot without having to monkey patch this gem. Add them to your `lita_config.rb` with the `add_meme` method:
35
+
36
+ ```rb
37
+ Lita::Handlers::ImgflipMemes.add_meme(
38
+ template_id: 61546,
39
+ pattern: /(brace yoursel[^\s]+) (.*)/i,
40
+ help: 'brace yourselves, <text>')
41
+ ```
42
+
43
+ Note that the `pattern` needs to be a regex and it needs to capture two strings. If you don't have two pairs of parens in your regex you're gonna have a bad time.
44
+
33
45
  ## Usage
34
46
 
35
47
  ```
@@ -11,14 +11,7 @@ module Lita
11
11
 
12
12
  API_URL = 'https://api.imgflip.com/caption_image'
13
13
 
14
- TEMPLATES = [
15
- { template_id: 101470, pattern: /^aliens()\s+(.+)/i, help: 'Ancient aliens guy' },
16
- { template_id: 61579, pattern: /(one does not simply) (.*)/i, help: 'one does not simply walk into mordor' },
17
- ]
18
-
19
- TEMPLATES.each do |t|
20
- route t.fetch(:pattern), :make_meme, command: true, help: t.fetch(:help)
21
- end
14
+ @@_templates = []
22
15
 
23
16
  def make_meme(message)
24
17
  line1, line2 = extract_meme_text(message.match_data)
@@ -41,7 +34,7 @@ module Lita
41
34
  end
42
35
 
43
36
  def find_template(pattern)
44
- template = TEMPLATES.select { |t| t.fetch(:pattern) == pattern }.first
37
+ template = registered_templates.select { |t| t.fetch(:pattern) == pattern }.first
45
38
  raise ArgumentError if template.nil?
46
39
  return template
47
40
  end
@@ -68,6 +61,23 @@ module Lita
68
61
  image = parsed.fetch('data', {}).fetch('url')
69
62
  end
70
63
 
64
+ def self.add_meme(template_id:, pattern:, help:)
65
+ @@_templates << { template_id: template_id, pattern: pattern, help: help }
66
+
67
+ route pattern, :make_meme, help: help
68
+ end
69
+
70
+ def registered_templates
71
+ self.class.registered_templates
72
+ end
73
+
74
+ def self.registered_templates
75
+ @@_templates
76
+ end
77
+
78
+ add_meme(template_id: 101470, pattern: /^aliens()\s+(.+)/i, help: 'Ancient aliens guy')
79
+ add_meme(template_id: 61579, pattern: /(one does not simply) (.*)/i, help: 'one does not simply walk into mordor')
80
+
71
81
  Lita.register_handler(self)
72
82
  end
73
83
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-imgflip-memes"
3
- spec.version = "1.0.1"
3
+ spec.version = "1.1.1"
4
4
  spec.authors = ["Daniel J. Pritchett"]
5
5
  spec.email = ["dpritchett@gmail.com"]
6
6
  spec.description = "Turns chatbot input text into meme images"
@@ -33,7 +33,7 @@ describe Lita::Handlers::ImgflipMemes, lita_handler: true do
33
33
  end
34
34
 
35
35
  describe ':extract_meme_text' do
36
- let(:matchers) { described_class::TEMPLATES }
36
+ let(:matchers) { described_class.registered_templates }
37
37
 
38
38
  it 'can properly match no-first-line inputs' do
39
39
  matcher = matchers.select { |t| t.fetch(:template_id) == 101470 }.first
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-imgflip-memes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Pritchett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-12 00:00:00.000000000 Z
11
+ date: 2017-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita