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 +4 -4
- data/.travis.yml +1 -1
- data/README.md +12 -0
- data/lib/lita/handlers/imgflip_memes.rb +19 -9
- data/lita-imgflip-memes.gemspec +1 -1
- data/spec/lita/handlers/imgflip_memes_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61806a949d88cdd70342fc2f2991494b1411fee0
|
4
|
+
data.tar.gz: 8897c43080275c3b72c5b0abb01267668fe2792c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc6ecfef1d344bf24ddb2242466398e552dd03b67aa156138d7f0ec4e4fd9967e3d4d74960b8ac45906eccca969f52e761607e704927f5efa618a18e6f6ccf6
|
7
|
+
data.tar.gz: 6fa2d4a56645b08a1bedc17a551cbebad59c7dacca0d9eed71ecb9333530671324d0e4ce502134e12ccd8f8ad98f6f1ed26c9ed293befbe0709091e465067ffe
|
data/.travis.yml
CHANGED
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
|
-
|
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 =
|
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
|
data/lita-imgflip-memes.gemspec
CHANGED
@@ -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
|
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.
|
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-
|
11
|
+
date: 2017-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|