hibot 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +9 -2
- data/hibot.gemspec +2 -2
- data/lib/api/giphy.rb +24 -0
- data/lib/api/spotify.rb +1 -0
- data/lib/hibot.rb +3 -1
- data/lib/hibot/helpers/configuration.rb +6 -0
- data/lib/hibot/plugins/giphy.rb +13 -0
- data/lib/hibot/plugins/spotify.rb +3 -4
- data/spec/api/giphy_spec.rb +18 -0
- data/spec/api/spotify_spec.rb +4 -0
- data/spec/helpers/configuration_spec.rb +11 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20c6d76c9963fa2fac68bf484003d065d071fb78
|
4
|
+
data.tar.gz: c5ad3bf5f78f41aaa8333833aec2b0f8841496a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1f9ea06d13f11ee04c7378910206fe42d2024ff0058d5c71b649757b599c6f77867a2063aae2704d4037ac6e68630ff2752f06a5ed06fa36205d03d037bbc43
|
7
|
+
data.tar.gz: fbaf53d4166bffd1c900a811753d74bfc758cbc13d8bb6617a0851d0705614f5bffb1ea1215f4727178eed4e69cfee24de1332a90868f3e0cef218424e2685ad
|
data/README.md
CHANGED
@@ -28,8 +28,6 @@ Then, just run the hibot binary to launch the bot. If you changed to default hib
|
|
28
28
|
|
29
29
|
## Plugins
|
30
30
|
|
31
|
-
At the moment, the following plugins are available :
|
32
|
-
|
33
31
|
To use a plugin, first you have to add it to the hibotrc file. Then configure the plugin if some extra configuration is needed. Here is the plugin list and the instructions per plugin :
|
34
32
|
|
35
33
|
1. Hibot::Spotify : allows you to parse Spotify uri when pasted in a channel or to search through Spotify's API some data.
|
@@ -44,6 +42,15 @@ To use this plugin, you have to create a spotify application. You can do it from
|
|
44
42
|
:client_secret: your_client_secret
|
45
43
|
```
|
46
44
|
|
45
|
+
2. Hibot::Giphy : allows you to get random gif uri matching your query
|
46
|
+
|
47
|
+
To use this plugin, you have to request an API key more information about how to get a key [here](https://github.com/giphy/GiphyAPI#access-and-api-keys). When you have your key, complete the hibotrc file with that structure :
|
48
|
+
|
49
|
+
```yaml
|
50
|
+
:Hibot::Giphy:
|
51
|
+
:api_key: your_api_key
|
52
|
+
```
|
53
|
+
|
47
54
|
## Contribute
|
48
55
|
1. Fork it
|
49
56
|
2. Dev it
|
data/hibot.gemspec
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'hibot'
|
5
|
-
s.version = '0.0.
|
6
|
-
s.date = '2015-04-
|
5
|
+
s.version = '0.0.2'
|
6
|
+
s.date = '2015-04-21'
|
7
7
|
s.summary = "IRC bot supporting multiple services."
|
8
8
|
s.description = "IRC bot supporting multiple services like spotify, giphy and so on."
|
9
9
|
s.authors = ["Nicolas Collard"]
|
data/lib/api/giphy.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module API
|
2
|
+
module Giphy
|
3
|
+
WS_URL = "http://api.giphy.com/v1/gifs/search"
|
4
|
+
URI_REGEX = /spotify:([a-z]+):(\w+)/
|
5
|
+
|
6
|
+
def search(query)
|
7
|
+
puts "dans le seeeeaaartch !!!"
|
8
|
+
query = query.gsub('!gsearch', '').strip
|
9
|
+
# Check that parameters are correct or return the corresponding error
|
10
|
+
return "Please provide something to search" if query.nil? || query == ""
|
11
|
+
|
12
|
+
# Perform the search and return the result
|
13
|
+
result = ""
|
14
|
+
response = HTTParty.get("#{WS_URL}?q=#{URI.encode(query)}&api_key=#{@@api_key}")
|
15
|
+
if response['data'] && response['data'].count > 0
|
16
|
+
gif = response['data'].first
|
17
|
+
result = "Check this : #{gif['url']}"
|
18
|
+
else
|
19
|
+
result = 'Nothing found with that parameter.'
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/api/spotify.rb
CHANGED
@@ -6,6 +6,7 @@ module API
|
|
6
6
|
|
7
7
|
def search(query)
|
8
8
|
# Check that parameters are correct or return the corresponding error
|
9
|
+
query = query.gsub('!ssearch', '').strip
|
9
10
|
type, q = query.split(' ')
|
10
11
|
return "Invalid search request. You have to provide a valid type (artist, album or track) and then your query" if type.nil? || q.nil?
|
11
12
|
return "Bad request. Allowed types are album, artist and track." unless PERMITTED_TYPES.include?(type)
|
data/lib/hibot.rb
CHANGED
@@ -6,7 +6,9 @@ require 'rainbow'
|
|
6
6
|
# custom classes
|
7
7
|
require 'hibot/helpers/configuration'
|
8
8
|
require 'api/spotify'
|
9
|
+
require 'api/giphy'
|
9
10
|
require 'hibot/plugins/spotify'
|
11
|
+
require 'hibot/plugins/giphy'
|
10
12
|
|
11
13
|
|
12
14
|
module Hibot
|
@@ -25,7 +27,7 @@ module Hibot
|
|
25
27
|
c.plugins.plugins = []
|
26
28
|
config[:general]['plugins.plugins'.to_sym].each do |plugin|
|
27
29
|
c.plugins.plugins << Object.const_get(plugin)
|
28
|
-
end
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -3,12 +3,11 @@ module Hibot
|
|
3
3
|
include Cinch::Plugin
|
4
4
|
include API::Spotify
|
5
5
|
|
6
|
-
match
|
6
|
+
match /ssearch/, {method: :query}
|
7
7
|
match API::Spotify::URI_REGEX, {method: :parse, use_prefix: false}
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
result = search(m.message.gsub('!search', '').split)
|
9
|
+
def query(m)
|
10
|
+
result = search(m.message)
|
12
11
|
m.reply result
|
13
12
|
end
|
14
13
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec.describe API::Giphy do
|
2
|
+
let(:obj) { Object.new.extend(described_class) }
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
config = Hibot.configure({path: File.expand_path("../../hibotrc", __FILE__)})
|
6
|
+
Hibot.configure_hibot_giphy(config['Hibot::Giphy'.to_sym])
|
7
|
+
end
|
8
|
+
|
9
|
+
context "parse_uri method" do
|
10
|
+
it "should return a message with an url if some gifs match the query" do
|
11
|
+
expect(obj.search('funny cat')).to_not eq("Nothing found with that parameter.")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return an error message if none gif is found with that query" do
|
15
|
+
expect(obj.search('foobartest')).to eq("Nothing found with that parameter.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/api/spotify_spec.rb
CHANGED
@@ -11,6 +11,10 @@ RSpec.describe API::Spotify do
|
|
11
11
|
expect(obj.parse_uri('spotify:track:0YQznyH9mJn6UTwWFHqy4b')).to eq('Nicolas Jaar - El Bandido')
|
12
12
|
end
|
13
13
|
|
14
|
+
it "should return a result if the uri matches with an artist" do
|
15
|
+
expect(obj.parse_uri('spotify:artist:7dGJo4pcD2V6oG8kP0tJRR')).to eq('Eminem')
|
16
|
+
end
|
17
|
+
|
14
18
|
it "should return nil if the uri doesn't match with any results" do
|
15
19
|
expect(obj.parse_uri('spotify:track:xxxxxxxxxxxxxxxxxx')).to eq(nil)
|
16
20
|
end
|
@@ -54,4 +54,15 @@ RSpec.describe Configuration do
|
|
54
54
|
expect(API::Spotify.class_variable_get(:@@bar)).to eq('foo')
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
describe "configure the gihpy plugin" do
|
59
|
+
it "should create class variable for each options" do
|
60
|
+
opts = {foo: "bar", bar: "foo"}
|
61
|
+
obj.configure_hibot_giphy(opts)
|
62
|
+
expect(API::Giphy.class_variable_defined?(:@@foo)).to eq(true)
|
63
|
+
expect(API::Giphy.class_variable_get(:@@foo)).to eq('bar')
|
64
|
+
expect(API::Giphy.class_variable_defined?(:@@bar)).to eq(true)
|
65
|
+
expect(API::Giphy.class_variable_get(:@@bar)).to eq('foo')
|
66
|
+
end
|
67
|
+
end
|
57
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hibot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Collard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cinch
|
@@ -94,11 +94,14 @@ files:
|
|
94
94
|
- Rakefile
|
95
95
|
- bin/hibot
|
96
96
|
- hibot.gemspec
|
97
|
+
- lib/api/giphy.rb
|
97
98
|
- lib/api/spotify.rb
|
98
99
|
- lib/config.rb
|
99
100
|
- lib/hibot.rb
|
100
101
|
- lib/hibot/helpers/configuration.rb
|
102
|
+
- lib/hibot/plugins/giphy.rb
|
101
103
|
- lib/hibot/plugins/spotify.rb
|
104
|
+
- spec/api/giphy_spec.rb
|
102
105
|
- spec/api/spotify_spec.rb
|
103
106
|
- spec/foo
|
104
107
|
- spec/helpers/configuration_spec.rb
|
@@ -128,6 +131,7 @@ signing_key:
|
|
128
131
|
specification_version: 4
|
129
132
|
summary: IRC bot supporting multiple services.
|
130
133
|
test_files:
|
134
|
+
- spec/api/giphy_spec.rb
|
131
135
|
- spec/api/spotify_spec.rb
|
132
136
|
- spec/foo
|
133
137
|
- spec/helpers/configuration_spec.rb
|