lita-imgflip 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29c04aa83dc0ff2a4d23e86d902bf633f943583b
4
+ data.tar.gz: 01e46b4cbebaae7cd055eec98a03ea4a73aeda7b
5
+ SHA512:
6
+ metadata.gz: b9766c86cf8af30d0aefba2d2e228af957dc082101f8764988ccf0f42110b4b17bfae7cf5e772a4d75c7cd3357d4ad20540c80cac3343ba4f4ce335b6f57ed67
7
+ data.tar.gz: a098b76d78b5ad19e66a476402c1c6dd617aff0f1916a5c2f28c171b6858f567adf4cb9c3a4560318ff86522743a3e36101ada9f6794d06eaef4c229d52f8a06
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rspec
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Henrik Sjökvist
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # lita-imgflip
2
+
3
+ [![Build Status](https://travis-ci.org/henrrrik/lita-imgflip.png)](https://travis-ci.org/henrrrik/lita-imgflip)
4
+ [![Code Climate](https://codeclimate.com/github/henrrrik/lita-imgflip.png)](https://codeclimate.com/github/henrrrik/lita-imgflip)
5
+ [![Coverage Status](https://coveralls.io/repos/henrrrik/lita-imgflip/badge.png)](https://coveralls.io/r/henrrrik/lita-imgflip)
6
+
7
+ **lita-imgflip** is a handler for [Lita](https://github.com/jimmycuadra/lita) that generates meme images using imgflip.com. The code is based on [lita-memgen](https://github.com/webdestroya/lita-memegen).
8
+
9
+ ## Installation
10
+
11
+ Add lita-imgflip to your Lita instance's Gemfile:
12
+
13
+ ``` ruby
14
+ gem "lita-imgflip"
15
+ ```
16
+
17
+ ## Configuration
18
+
19
+ You will need to register an account on imgflip.com and provide the username/password for the account.
20
+
21
+ ```
22
+ Lita.configure do |config|
23
+
24
+ # This requires that all memes be sent as commands. If this is false, the bot will listen in the channel
25
+ config.handlers.imgflip.command_only = true
26
+
27
+ config.handlers.imgflip.username = 'username'
28
+ config.handlers.imgflip.password = 'password'
29
+ end
30
+ ```
31
+
32
+ ## Usage
33
+
34
+
35
+ * `Y U NO <text>` - Generates the Y U NO GUY with the bottom caption of <text>
36
+ * `I don't always <something> but when i do <text>` - Generates The Most Interesting man in
37
+ * `<text> (SUCCESS|NAILED IT)` - Generates success kid with the top caption of <text>
38
+ * `<text> ALL the <things>` - Generates ALL THE THINGS
39
+ * `<text> TOO DAMN <high>` - Generates THE RENT IS TOO DAMN HIGH guy
40
+ * `good news everyone! <news>` - Generates Professor Farnsworth
41
+ * `khanify <text>` - TEEEEEEEEEEEEEEEEEXT!
42
+ * `Not sure if <text> or <text>` - Generates Futurama Fry
43
+ * `Yo dawg <text> so <text>` - Generates Yo Dawg
44
+ * `ALL YOUR <text> ARE BELONG TO US` - Generates Zero Wing with the caption of <text>
45
+ * `<text> you're gonna have a bad time` - Bad Time Ski Instructor
46
+ * `one does not simply <text>` - Lord of the Rings Boromir
47
+ * `grumpy cat <text>, <text>` - Grumpy cat
48
+ * `it looks like (you|you're) <text>` - Generates Clippy
49
+ * `AM I THE ONLY ONE AROUND HERE <text>` - The Big Lebowski
50
+ * `<text> NOT IMPRESSED` - Generates McKayla Maroney
51
+ * `PREPARE YOURSELF <text>` - Generates GoT
52
+ * `WHAT IF I TOLD YOU <text>` - Generates Morpheus
53
+ * `<text> BETTER DRINK MY OWN PISS` - Generates Bear Grylls
54
+ * `khanify <text>` - Generates Captain Kirk
55
+
56
+ ## License
57
+
58
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require "lita/handlers/imgflip"
@@ -0,0 +1,160 @@
1
+ require "lita"
2
+
3
+ module Lita
4
+ module Handlers
5
+ class Imgflip < Handler
6
+
7
+ def self.default_config(config)
8
+ config.command_only = true
9
+ config.username = nil
10
+ config.password = nil
11
+ end
12
+
13
+ route %r{(Y U NO) (.+)}i, :meme_y_u_no, help: { "Y U NO..." => "generates Y U NO meme"}
14
+ route %r{(I DON'?T ALWAYS .*) (BUT WHEN I DO,? .*)}i, :meme_i_dont_always, help: { "I DON'T ALWAYS .. BUT WHEN I DO, .." => "generates I DON'T ALWAY meme"}
15
+ route %r{(.*)(O\s?RLY\??.*)}i, :meme_orly, help: { "..O RLY.." => "generates O RLY meme" }
16
+ route %r{(.*)(SUCCESS|NAILED IT.*)}, :meme_success, help: { "..SUCCESS.." => "(case sensitive) generates SUCCESS meme", "..NAILED IT.." => "generates NAILED IT meme" }
17
+ route %r{(.*) (ALL the .*)}, :meme_all_the, help: { "ALL the.." => "(case sensitive) generates ALL the <things> meme" }
18
+ route %r{(.*) (\w+\sTOO DAMN .*)}i, :meme_too_damn, help: { "TOO DAMN.." => "generates TOO DAMN meme" }
19
+ route %r{(GOOD NEWS EVERYONE[,.!]?) (.*)}i, :meme_good_news, help: { "GOOD NEWS EVERYONE.." => "generates GOOD NEWS EVERYONE meme" }
20
+ route %r{(NOT SURE IF .*) (OR .*)}i, :meme_not_sure_if, help: { "NOT SURE IF.. OR.." => "generates NOT SURE IF .. OR meme" }
21
+ route %r{(YO DAWG .*) (SO .*)}i, :meme_yo_dawg, help: { "YO DAWG.." => "generates YO DAWG meme" }
22
+ route %r{(ALL YOUR .*) (ARE BELONG TO US)}i, :meme_are_belong, help: { "ALL YOUR.. ARE BELONG TO US" => "generates ALL YOUR.. ARE BELONG TO US meme" }
23
+ route %r{(.*) (You'?re gonna have a bad time)}i, :meme_bad_time, help: { ".. You're going have a bad time" => "generates You're gonna have a bad time meme" }
24
+ route %r{(one does not simply) (.*)}i, :meme_simply, help: { "one does not simply.." => "generates one does not simply.. meme" }
25
+ route %r{(grumpy cat) (.*),(.*)}i, :meme_grumpy_cat, help: { "grumpy cat .. , .." => "generates grumpy cat .. , .. meme" }
26
+ route %r{(it looks like you're|it looks like you) (.*)}i, :meme_looks_like, help: { "it looks like you're .." => "generates it looks like you're .. meme", "it looks like you.." => "(case insensitive) generates it looks like you.. meme" }
27
+ route %r{(AM I THE ONLY ONE AROUND HERE) (.*)}i, :meme_am_i_only, help: { "AM I THE ONLY ONE AROUND HERE.." => "generates AM I THE ONLY ONE AROUND HERE.. meme" }
28
+ route %r{(.*)(NOT IMPRESSED*)}i, :meme_not_impressed, help: { "..NOT IMPRESSED" => "generates ..NOT IMPRESSED meme" }
29
+ route %r{(PREPARE YOURSELF) (.*)}i, :meme_prepare_yourself, help: { "PREPARE YOURSELF.." => "generates PREPARE YOURSELF.. meme" }
30
+ route %r{(WHAT IF I TOLD YOU) (.*)}i, :meme_what_if_i, help: { "WHAT IF I TOLD YOU.." => "generates WHAT IF I TOLD YOU.. meme" }
31
+ route %r{(.*) (BETTER DRINK MY OWN PISS)}i, :meme_better_drink, help: { "..BETTER DRINK MY OWN PISS" => "generates ..BETTER DRINK MY OWN PISS meme" }
32
+ route %r{^khanify (.*)}i, :meme_khanify, help: { "khanify ..." => "generates khan meme" }
33
+
34
+
35
+ def meme_y_u_no(response)
36
+ generate_meme(response, 61527)
37
+ end
38
+
39
+ def meme_i_dont_always(response)
40
+ generate_meme(response, 61532)
41
+ end
42
+
43
+ def meme_success(response)
44
+ generate_meme(response, 61544)
45
+ end
46
+
47
+ def meme_all_the(response)
48
+ generate_meme(response, 61533)
49
+ end
50
+
51
+ def meme_too_damn(response)
52
+ generate_meme(response, 61580)
53
+ end
54
+
55
+ def meme_good_news(response)
56
+ generate_meme(response, 7163250)
57
+ end
58
+
59
+ def meme_not_sure_if(response)
60
+ generate_meme(response, 61520)
61
+ end
62
+
63
+ def meme_yo_dawg(response)
64
+ generate_meme(response, 101716)
65
+ end
66
+
67
+ def meme_are_belong(response)
68
+ generate_meme(response, 4503404)
69
+ end
70
+
71
+ def meme_fuck_you(response)
72
+ generate_meme(response, 165248)
73
+ end
74
+
75
+ def meme_bad_time(response)
76
+ generate_meme(response, 100951)
77
+ end
78
+
79
+ def meme_simply(response)
80
+ generate_meme(response, 61579)
81
+ end
82
+
83
+ def meme_grumpy_cat(response)
84
+ generate_meme(response, 405658)
85
+ end
86
+
87
+ def meme_looks_like(response)
88
+ generate_meme(response, 7842373)
89
+ end
90
+
91
+ def meme_am_i_only(response)
92
+ generate_meme(response, 259680)
93
+ end
94
+
95
+ def meme_not_impressed(response)
96
+ generate_meme(response, 117402)
97
+ end
98
+
99
+ def meme_prepare_yourself(response)
100
+ generate_meme(response, 6774155)
101
+ end
102
+
103
+ def meme_what_if_i(response)
104
+ generate_meme(response, 100947)
105
+ end
106
+
107
+ def meme_better_drink(response)
108
+ generate_meme(response, 61548)
109
+ end
110
+
111
+ def meme_khanify(response)
112
+ generate_meme(response, 2743696, text0: "", text1: khanify(response.matches[0][0]))
113
+ end
114
+
115
+
116
+ private
117
+
118
+ def khanify(phrase)
119
+ shouty_phrase = phrase.upcase
120
+ last_vowel_index = shouty_phrase.rindex(/[AEIOU]/) || -1 # default to final consonant
121
+ last_vowel = shouty_phrase[last_vowel_index]
122
+ "#{shouty_phrase[0..last_vowel_index]}#{10.times.map{ last_vowel }.join}#{shouty_phrase[last_vowel_index..-1]}!!!!"
123
+ end
124
+
125
+ def generate_meme(response, template_id, text0: nil, text1: nil)
126
+
127
+ text0 ||= response.matches[0][0]
128
+ text1 ||= response.matches[0][1]
129
+
130
+ http_resp = http.get(
131
+ 'http://api.imgflip.com/caption_image',
132
+ username: Lita.config.handlers.imgflip.username,
133
+ password: Lita.config.handlers.imgflip.password,
134
+ template_id: template_id,
135
+ text0: text0,
136
+ text1: text1
137
+ )
138
+
139
+ if http_resp.status == 200
140
+ result = MultiJson.load(http_resp.body)
141
+
142
+ if result['success']
143
+ response.reply result['data']['url']
144
+ else
145
+ Lita.logger.error "#{self.class}: Unable to generate a meme image: #{result['error_message']}"
146
+ response.reply "Error: #{result['error_message']}"
147
+ end
148
+
149
+ else
150
+ Lita.logger.error "#{self.class}: Unable to generate a meme image: #{http_resp.body}"
151
+ response.reply "Error: Unable to generate a meme image"
152
+ end
153
+
154
+ end
155
+
156
+ end
157
+
158
+ Lita.register_handler(Imgflip)
159
+ end
160
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-imgflip"
3
+ spec.version = "1.0.0"
4
+ spec.authors = ["Henrik Sjökvist"]
5
+ spec.email = ["henrik.sjokvist@gmail.com"]
6
+ spec.description = %q{A Lita handler for generating meme images using imgflip.com.}
7
+ spec.summary = %q{A Lita handler for generating meme images using imgflip.com.}
8
+ spec.homepage = "https://github.com/henrrrik/lita-imgflip"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", "~> 2.0"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rspec", "~> 2.14"
21
+ spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "coveralls"
23
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Imgflip, lita_handler: true do
4
+ it { routes_command("Y U NO BLAH").to(:meme_y_u_no) }
5
+ it { routes_command("i don't always fart but when i do, i do it loud").to(:meme_i_dont_always) }
6
+ it { routes_command("blah BETTER DRINK MY OWN PISS").to(:meme_better_drink) }
7
+ it { routes_command("khanify blah").to(:meme_khanify) }
8
+
9
+ it "sets the username and password to nil by default" do
10
+ expect(Lita.config.handlers.imgflip.username).to be_nil
11
+ expect(Lita.config.handlers.imgflip.password).to be_nil
12
+ end
13
+
14
+ end
@@ -0,0 +1,10 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-imgflip"
10
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-imgflip
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Henrik Sjökvist
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Lita handler for generating meme images using imgflip.com.
98
+ email:
99
+ - henrik.sjokvist@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .ruby-version
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - lib/lita-imgflip.rb
112
+ - lib/lita/handlers/imgflip.rb
113
+ - lita-imgflip.gemspec
114
+ - spec/lita/handlers/imgflip_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/henrrrik/lita-imgflip
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.14
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: A Lita handler for generating meme images using imgflip.com.
140
+ test_files:
141
+ - spec/lita/handlers/imgflip_spec.rb
142
+ - spec/spec_helper.rb