lita-hashtag 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/lib/lita/handlers/hashtag.rb +98 -0
- data/lib/lita-hashtag.rb +7 -0
- data/lita-hashtag.gemspec +23 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/hashtag_spec.rb +4 -0
- data/spec/spec_helper.rb +6 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 996a89b7c3ab87863f179b919cb8421a1da24e3f
|
4
|
+
data.tar.gz: 0aeba2b201c49c7c3a7ea1056c8dd5274ff99690
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ba17fd5aa0794283536cbe9b2229d9edcdcd9659863b7207a79238a61f934432218668305c750c47388ad54362e889677035dfb0ce6040c9811a760cc676fc4
|
7
|
+
data.tar.gz: 9d8dd45a7d723af11e8787e479579a8f8124f499e80d9ad927b2e6aad4e9a44cc06081bcc4b957cee1efd7e1a21828f5d3d6623c18398878a168b293b2b8a898
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2015 Richard Li
|
2
|
+
Copyright (c) 2013 Jordan Killpack
|
3
|
+
Copyright (c) 2013 Jimmy Cuadra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# lita-hashtag
|
2
|
+
|
3
|
+
Let lita bot respond with a random image to '#', and a gif from giphy to '##'.
|
4
|
+
|
5
|
+
This is literally a simple stitch work that combine the code from
|
6
|
+
[lita-google-images](https://github.com/jimmycuadra/lita-google-images) and
|
7
|
+
[lita-giphy](https://github.com/killpack/lita-giphy) and make them respond to
|
8
|
+
'#' and '##'.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add lita-hashtag to your Lita instance's Gemfile:
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
gem "lita-hashtag"
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
### Optional
|
22
|
+
|
23
|
+
* `config.handlers.hashtag.safe_search` - (String, Symbol) - The safe search
|
24
|
+
setting to use when querying for images. Possible values are `:active`,
|
25
|
+
`:moderate`, and `:off`. **Default:** `:active`.
|
26
|
+
* `config.handlers.hashtag.giphy_api_key` - String - Your Giphy API key. You can
|
27
|
+
either email the devs for a personal API key, or you can use the default
|
28
|
+
public beta key-- dc6zaTOxFJmzC. **Default:** `dc6zaTOxFJmzC`
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
```
|
33
|
+
You: #success
|
34
|
+
Lita: http://ptb-uploads-prod.s3.amazonaws.com/blog/wp-content/uploads/2015/02/success.jpg
|
35
|
+
```
|
36
|
+
|
37
|
+
```
|
38
|
+
You: ##victory
|
39
|
+
Lita: http://media2.giphy.com/media/PzOm3LPWu7fJS/giphy.gif
|
40
|
+
```
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class Hashtag < Handler
|
4
|
+
URL = "https://ajax.googleapis.com/ajax/services/search/images"
|
5
|
+
GIF_URL = "http://api.giphy.com/v1/gifs/search"
|
6
|
+
VALID_SAFE_VALUES = %w(active moderate off)
|
7
|
+
|
8
|
+
config :safe_search, types: [String, Symbol], default: :active do
|
9
|
+
validate do |value|
|
10
|
+
unless VALID_SAFE_VALUES.include?(value.to_s.strip)
|
11
|
+
"valid values are :active, :moderate, or :off"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
config :giphy_api_key, type: String, default: 'dc6zaTOxFJmzC'
|
17
|
+
|
18
|
+
route(/^#(.+)/, :fetch, command: false, help: {
|
19
|
+
"#QUERY" => "Displays a random image from Google Images for query.",
|
20
|
+
"##QUERY" => "Display a random gif from giphy.com for query"
|
21
|
+
})
|
22
|
+
|
23
|
+
def fetch(response)
|
24
|
+
query = response.matches[0][0]
|
25
|
+
|
26
|
+
if query[0] == '#'
|
27
|
+
response.reply get_gif(query)
|
28
|
+
else
|
29
|
+
http_response = http.get(
|
30
|
+
URL,
|
31
|
+
v: "1.0",
|
32
|
+
q: query,
|
33
|
+
safe: config.safe_search,
|
34
|
+
rsz: 8
|
35
|
+
)
|
36
|
+
|
37
|
+
data = MultiJson.load(http_response.body)
|
38
|
+
|
39
|
+
if data["responseStatus"] == 200
|
40
|
+
choice = data["responseData"]["results"].sample
|
41
|
+
if choice
|
42
|
+
response.reply ensure_extension(choice["unescapedUrl"])
|
43
|
+
else
|
44
|
+
response.reply %{No images found for "#{query}".}
|
45
|
+
end
|
46
|
+
else
|
47
|
+
reason = data["responseDetails"] || "unknown error"
|
48
|
+
Lita.logger.warn(
|
49
|
+
"Couldn't get image from Google: #{reason}"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def ensure_extension(url)
|
58
|
+
if [".gif", ".jpg", ".jpeg", ".png"].any? { |ext| url.end_with?(ext) }
|
59
|
+
url
|
60
|
+
else
|
61
|
+
"#{url}#.png"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_gif(query)
|
66
|
+
process_response(http.get(
|
67
|
+
GIF_URL,
|
68
|
+
q: query,
|
69
|
+
api_key: config.giphy_api_key
|
70
|
+
), query)
|
71
|
+
end
|
72
|
+
|
73
|
+
def process_response(http_response, query)
|
74
|
+
data = MultiJson.load(http_response.body)
|
75
|
+
|
76
|
+
if data["meta"]["status"] == 200
|
77
|
+
choice = data["data"].sample
|
78
|
+
if choice.nil?
|
79
|
+
reply_text = "I couldn't find anything for '#{query}'!"
|
80
|
+
else
|
81
|
+
reply_text = choice["images"]["original"]["url"]
|
82
|
+
end
|
83
|
+
else
|
84
|
+
reason = data["meta"]["error_message"] || "unknown error"
|
85
|
+
Lita.logger.warn(
|
86
|
+
"Couldn't get image from Giphy: #{reason}"
|
87
|
+
)
|
88
|
+
reply_text = "Giphy request failed-- please check my logs."
|
89
|
+
end
|
90
|
+
|
91
|
+
reply_text
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
Lita.register_handler(Hashtag)
|
97
|
+
end
|
98
|
+
end
|
data/lib/lita-hashtag.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-hashtag"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["Richard Li"]
|
5
|
+
spec.email = ["evilcat@wisewolfsolutions.com"]
|
6
|
+
spec.description = %q{Let lita bot respond to #'s}
|
7
|
+
spec.summary = %q{Let lita bot respond to #'s}
|
8
|
+
spec.homepage = "https://github.com/ecwws/lita-hashtag"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", ">= 4.1"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rack-test"
|
22
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
23
|
+
end
|
data/locales/en.yml
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-hashtag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Richard Li
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-07 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: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
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: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.0
|
83
|
+
description: 'Let lita bot respond to #''s'
|
84
|
+
email:
|
85
|
+
- evilcat@wisewolfsolutions.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/lita-hashtag.rb
|
96
|
+
- lib/lita/handlers/hashtag.rb
|
97
|
+
- lita-hashtag.gemspec
|
98
|
+
- locales/en.yml
|
99
|
+
- spec/lita/handlers/hashtag_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
homepage: https://github.com/ecwws/lita-hashtag
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata:
|
105
|
+
lita_plugin_type: handler
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: 'Let lita bot respond to #''s'
|
126
|
+
test_files:
|
127
|
+
- spec/lita/handlers/hashtag_spec.rb
|
128
|
+
- spec/spec_helper.rb
|