robut 0.3.0 → 0.4.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.
- data/.travis.yml +11 -0
- data/Gemfile +2 -3
- data/README.rdoc +38 -19
- data/examples/Chatfile +10 -4
- data/lib/robut.rb +3 -0
- data/lib/robut/connection.rb +10 -72
- data/lib/robut/plugin.rb +94 -13
- data/lib/robut/plugin/echo.rb +3 -13
- data/lib/robut/plugin/google_images.rb +17 -0
- data/lib/robut/plugin/help.rb +7 -15
- data/lib/robut/plugin/meme.rb +22 -53
- data/lib/robut/plugin/pick.rb +18 -0
- data/lib/robut/plugin/ping.rb +3 -9
- data/lib/robut/plugin/quips.rb +60 -0
- data/lib/robut/plugin/say.rb +6 -12
- data/lib/robut/plugin/stock.rb +45 -0
- data/lib/robut/pm.rb +40 -0
- data/lib/robut/presence.rb +35 -0
- data/lib/robut/room.rb +30 -0
- data/lib/robut/version.rb +1 -1
- data/test/mocks/connection_mock.rb +2 -18
- data/test/mocks/presence_mock.rb +25 -0
- data/test/test_helper.rb +3 -1
- data/test/unit/connection_test.rb +58 -25
- data/test/unit/plugin/alias_test.rb +5 -4
- data/test/unit/plugin/echo_test.rb +5 -4
- data/test/unit/plugin/help_test.rb +4 -3
- data/test/unit/plugin/later_test.rb +7 -6
- data/test/unit/plugin/lunch_test.rb +6 -5
- data/test/unit/plugin/pick_test.rb +35 -0
- data/test/unit/plugin/ping_test.rb +4 -3
- data/test/unit/plugin/quips_test.rb +58 -0
- data/test/unit/plugin/say_test.rb +4 -3
- data/test/unit/plugin/weather_test.rb +15 -14
- data/test/unit/plugin_test.rb +62 -1
- data/test/unit/room_test.rb +51 -0
- metadata +28 -20
- data/lib/robut/plugin/rdio.rb +0 -96
- data/lib/robut/plugin/rdio/public/css/rdio.css +0 -141
- data/lib/robut/plugin/rdio/public/css/style.css +0 -79
- data/lib/robut/plugin/rdio/public/css/style_after.css +0 -42
- data/lib/robut/plugin/rdio/public/images/background.png +0 -0
- data/lib/robut/plugin/rdio/public/images/no-album.png +0 -0
- data/lib/robut/plugin/rdio/public/index.html +0 -43
- data/lib/robut/plugin/rdio/public/js/libs/dd_belatedpng.js +0 -13
- data/lib/robut/plugin/rdio/public/js/libs/jquery-1.5.1.min.js +0 -16
- data/lib/robut/plugin/rdio/public/js/libs/modernizr-1.7.min.js +0 -2
- data/lib/robut/plugin/rdio/public/js/rdio.js +0 -129
- data/lib/robut/plugin/rdio/public/js/script.js +0 -3
- data/lib/robut/plugin/rdio/server.rb +0 -57
@@ -5,7 +5,8 @@ class Robut::Plugin::SayTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@connection = Robut::ConnectionMock.new
|
8
|
-
@
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Say.new(@presence)
|
9
10
|
@plugin.instance_eval do
|
10
11
|
# Stub out system
|
11
12
|
def system(c); system_calls << c; end
|
@@ -15,13 +16,13 @@ class Robut::Plugin::SayTest < Test::Unit::TestCase
|
|
15
16
|
|
16
17
|
def test_says_stuff
|
17
18
|
@plugin.handle(Time.now, "@john", "@robut say stuff")
|
18
|
-
assert_equal [], @plugin.
|
19
|
+
assert_equal [], @plugin.reply_to.replies # shouldn't reply to the chat room
|
19
20
|
assert_equal ["say stuff"], @plugin.system_calls
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_doesnt_say_stuff
|
23
24
|
@plugin.handle(Time.now, "@john", "@robut ok don't say stuff")
|
24
|
-
assert_equal [], @plugin.
|
25
|
+
assert_equal [], @plugin.reply_to.replies
|
25
26
|
assert_equal [], @plugin.system_calls
|
26
27
|
end
|
27
28
|
|
@@ -7,7 +7,8 @@ class Robut::Plugin::WeatherTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def setup
|
9
9
|
@connection = Robut::ConnectionMock.new
|
10
|
-
@
|
10
|
+
@presence = Robut::PresenceMock.new(@connection)
|
11
|
+
@plugin = Robut::Plugin::Weather.new(@presence)
|
11
12
|
end
|
12
13
|
|
13
14
|
def teardown
|
@@ -16,15 +17,15 @@ class Robut::Plugin::WeatherTest < Test::Unit::TestCase
|
|
16
17
|
|
17
18
|
def test_handle_no_weather
|
18
19
|
@plugin.handle(Time.now, "John", "lunch?")
|
19
|
-
assert_equal( [], @plugin.
|
20
|
+
assert_equal( [], @plugin.reply_to.replies )
|
20
21
|
|
21
22
|
@plugin.handle(Time.now, "John", "?")
|
22
|
-
assert_equal( [], @plugin.
|
23
|
+
assert_equal( [], @plugin.reply_to.replies )
|
23
24
|
end
|
24
25
|
|
25
26
|
def test_handle_no_location_no_default
|
26
27
|
@plugin.handle(Time.now, "John", "weather?")
|
27
|
-
assert_equal( ["I don't have a default location!"], @plugin.
|
28
|
+
assert_equal( ["I don't have a default location!"], @plugin.reply_to.replies )
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_handle_no_location_default_set
|
@@ -32,19 +33,19 @@ class Robut::Plugin::WeatherTest < Test::Unit::TestCase
|
|
32
33
|
stub_request(:any, "http://www.google.com/ig/api?weather=Seattle").to_return(:body => File.open(File.expand_path("../../../fixtures/seattle.xml", __FILE__), "r").read)
|
33
34
|
|
34
35
|
@plugin.handle(Time.now, "John", "weather?")
|
35
|
-
assert_equal( ["Weather for Seattle, WA: Mostly Cloudy, 58F"], @plugin.
|
36
|
+
assert_equal( ["Weather for Seattle, WA: Mostly Cloudy, 58F"], @plugin.reply_to.replies )
|
36
37
|
end
|
37
38
|
|
38
39
|
def test_handle_location
|
39
40
|
stub_request(:any, "http://www.google.com/ig/api?weather=tacoma").to_return(:body => File.open(File.expand_path("../../../fixtures/tacoma.xml", __FILE__), "r").read)
|
40
41
|
|
41
42
|
@plugin.handle(Time.now, "John", "tacoma weather?")
|
42
|
-
assert_equal( ["Weather for Tacoma, WA: Cloudy, 60F"], @plugin.
|
43
|
+
assert_equal( ["Weather for Tacoma, WA: Cloudy, 60F"], @plugin.reply_to.replies )
|
43
44
|
end
|
44
45
|
|
45
46
|
def test_no_question_mark
|
46
47
|
@plugin.handle(Time.now, "John", "seattle weather")
|
47
|
-
assert_equal( [], @plugin.
|
48
|
+
assert_equal( [], @plugin.reply_to.replies )
|
48
49
|
end
|
49
50
|
|
50
51
|
def test_handle_day
|
@@ -52,7 +53,7 @@ class Robut::Plugin::WeatherTest < Test::Unit::TestCase
|
|
52
53
|
|
53
54
|
pretend_now_is(2011,"may",23,17) do
|
54
55
|
@plugin.handle(Time.now, "John", "Seattle weather tuesday?")
|
55
|
-
assert_equal( ["Forecast for Seattle, WA on Tue: Partly Cloudy, High: 67F, Low: 51F"], @plugin.
|
56
|
+
assert_equal( ["Forecast for Seattle, WA on Tue: Partly Cloudy, High: 67F, Low: 51F"], @plugin.reply_to.replies )
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -61,7 +62,7 @@ class Robut::Plugin::WeatherTest < Test::Unit::TestCase
|
|
61
62
|
|
62
63
|
pretend_now_is(2011,"may",23,17) do
|
63
64
|
@plugin.handle(Time.now, "John", "Seattle weather tomorrow?")
|
64
|
-
assert_equal( ["Forecast for Seattle, WA on Tue: Partly Cloudy, High: 67F, Low: 51F"], @plugin.
|
65
|
+
assert_equal( ["Forecast for Seattle, WA on Tue: Partly Cloudy, High: 67F, Low: 51F"], @plugin.reply_to.replies )
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
@@ -70,31 +71,31 @@ class Robut::Plugin::WeatherTest < Test::Unit::TestCase
|
|
70
71
|
|
71
72
|
pretend_now_is(2011,"may",23,17) do
|
72
73
|
@plugin.handle(Time.now, "John", "Seattle weather today?")
|
73
|
-
assert_equal( ["Forecast for Seattle, WA on Mon: Partly Cloudy, High: 59F, Low: 48F"], @plugin.
|
74
|
+
assert_equal( ["Forecast for Seattle, WA on Mon: Partly Cloudy, High: 59F, Low: 48F"], @plugin.reply_to.replies )
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
77
78
|
def test_handle_multi_word_location
|
78
79
|
stub_request(:any, "http://www.google.com/ig/api?weather=Las%20Vegas").to_return(:body => File.open(File.expand_path("../../../fixtures/las_vegas.xml", __FILE__), "r").read)
|
79
80
|
@plugin.handle(Time.now, "John", "Las Vegas weather?")
|
80
|
-
assert_equal( ["Weather for Las Vegas, NV: Mostly Cloudy, 83F"], @plugin.
|
81
|
+
assert_equal( ["Weather for Las Vegas, NV: Mostly Cloudy, 83F"], @plugin.reply_to.replies )
|
81
82
|
end
|
82
83
|
|
83
84
|
def test_handle_location_with_comma
|
84
85
|
stub_request(:any, "http://www.google.com/ig/api?weather=Las%20Vegas,%20NV").to_return(:body => File.open(File.expand_path("../../../fixtures/las_vegas.xml", __FILE__), "r").read)
|
85
86
|
@plugin.handle(Time.now, "John", "Las Vegas, NV weather?")
|
86
|
-
assert_equal( ["Weather for Las Vegas, NV: Mostly Cloudy, 83F"], @plugin.
|
87
|
+
assert_equal( ["Weather for Las Vegas, NV: Mostly Cloudy, 83F"], @plugin.reply_to.replies )
|
87
88
|
end
|
88
89
|
|
89
90
|
def test_handle_bad_location
|
90
91
|
stub_request(:any, "http://www.google.com/ig/api?weather=asdf").to_return(:body => File.open(File.expand_path("../../../fixtures/bad_location.xml", __FILE__), "r").read)
|
91
92
|
@plugin.handle(Time.now, "John", "asdf weather?")
|
92
|
-
assert_equal( ["I don't recognize the location: \"asdf\""], @plugin.
|
93
|
+
assert_equal( ["I don't recognize the location: \"asdf\""], @plugin.reply_to.replies )
|
93
94
|
end
|
94
95
|
|
95
96
|
def test_handle_bad_date
|
96
97
|
@plugin.handle(Time.now, "John", "Seattle weather asdf?")
|
97
|
-
assert_equal( ["I don't recognize the date: \"asdf\""], @plugin.
|
98
|
+
assert_equal( ["I don't recognize the date: \"asdf\""], @plugin.reply_to.replies )
|
98
99
|
end
|
99
100
|
|
100
101
|
end
|
data/test/unit/plugin_test.rb
CHANGED
@@ -4,10 +4,55 @@ class Robut::PluginTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
class HandrolledStubPlugin
|
6
6
|
include Robut::Plugin
|
7
|
+
|
8
|
+
match /^message sent to robut with anchor (\w+)/, :sent_to_me => true do |word|
|
9
|
+
reply word
|
10
|
+
end
|
11
|
+
|
12
|
+
match /^another message sent to robut with anchor (\w+)/, :sent_to_me => true do |word|
|
13
|
+
reply word
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "stop matcher - stop matching messages"
|
17
|
+
match /stop matcher/ do
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
match /stop matcher b/ do
|
22
|
+
reply "fail."
|
23
|
+
end
|
7
24
|
end
|
8
25
|
|
9
26
|
def setup
|
10
|
-
@plugin = HandrolledStubPlugin.new(
|
27
|
+
@plugin = HandrolledStubPlugin.new(
|
28
|
+
Robut::PresenceMock.new(
|
29
|
+
Robut::ConnectionMock
|
30
|
+
)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_sent_to_me_match
|
35
|
+
@plugin.handle(Time.now, "@john", "@robut message sent to robut with anchor pass")
|
36
|
+
assert_equal ["pass"], @plugin.reply_to.replies
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_match_other_message_sent_to_me
|
40
|
+
@plugin.handle(Time.now, "@john", "@robut another message sent to robut with anchor pass")
|
41
|
+
assert_equal ["pass"], @plugin.reply_to.replies
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_no_match_if_not_sent_to_me
|
45
|
+
@plugin.handle(Time.now, "@john", "message sent to robut with anchor pass")
|
46
|
+
assert_equal [], @plugin.reply_to.replies
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_returning_true_stops_matching
|
50
|
+
@plugin.handle(Time.now, "@john", "stop matcher b")
|
51
|
+
assert_equal [], @plugin.reply_to.replies
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_set_description
|
55
|
+
assert_equal ["stop matcher - stop matching messages"], @plugin.usage
|
11
56
|
end
|
12
57
|
|
13
58
|
def test_sent_to_me?
|
@@ -27,4 +72,20 @@ class Robut::PluginTest < Test::Unit::TestCase
|
|
27
72
|
assert_equal "do this @robut", @plugin.without_nick("do this @robut")
|
28
73
|
end
|
29
74
|
|
75
|
+
def test_sent_to_me_without_mention_configuration_option
|
76
|
+
setup_connection_without_mention_name
|
77
|
+
assert @plugin.sent_to_me?("@RobutTRobot hello there"), "sent_to_me? should match the standard HipChat mention format"
|
78
|
+
assert !@plugin.sent_to_me?("@Robut hello there"), "sent_to_me? should not match @robut if we don't have a mention name set"
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def setup_connection_without_mention_name
|
84
|
+
@plugin = HandrolledStubPlugin.new(
|
85
|
+
Robut::PresenceMock.new(
|
86
|
+
Robut::ConnectionMock.new(OpenStruct.new(:nick => 'Robut t. Robot'))
|
87
|
+
)
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
30
91
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/echo'
|
3
|
+
|
4
|
+
class MucMock
|
5
|
+
attr_accessor :messages, :room
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@messages = []
|
9
|
+
@room = ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def join(room)
|
13
|
+
@room = room
|
14
|
+
end
|
15
|
+
|
16
|
+
def send(message)
|
17
|
+
@messages << message
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_message(*args, &block)
|
21
|
+
if block_given?
|
22
|
+
@message_block = block
|
23
|
+
else
|
24
|
+
@message_block.call(args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class RoomTest < Test::Unit::TestCase
|
30
|
+
def setup
|
31
|
+
Robut::Plugin.plugins = [Robut::Plugin::Echo]
|
32
|
+
connection = Robut::ConnectionMock.new(OpenStruct.new(:nick => 'Dodo'))
|
33
|
+
@room = Robut::Room.new(connection, 'fake_room')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_room_receives_correct_message
|
37
|
+
message = 'Huzzah!'
|
38
|
+
@room.muc = MucMock.new
|
39
|
+
@room.join
|
40
|
+
|
41
|
+
@room.muc.on_message(Time.now, "Art Vandelay", "@dodo echo #{message}")
|
42
|
+
assert_equal @room.muc.messages.first.body, message
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_joining_the_right_room
|
46
|
+
@room.muc = MucMock.new
|
47
|
+
@room.join
|
48
|
+
|
49
|
+
assert_equal @room.muc.room, "#{@room.name}/#{@room.connection.config.nick}"
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: xmpp4r
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: 0.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.0
|
25
30
|
description: A simple plugin-enabled HipChat bot
|
26
31
|
email:
|
27
32
|
- justin@uberweiss.org
|
@@ -31,6 +36,7 @@ extensions: []
|
|
31
36
|
extra_rdoc_files: []
|
32
37
|
files:
|
33
38
|
- .gitignore
|
39
|
+
- .travis.yml
|
34
40
|
- Gemfile
|
35
41
|
- README.rdoc
|
36
42
|
- Rakefile
|
@@ -43,28 +49,22 @@ files:
|
|
43
49
|
- lib/robut/plugin/alias.rb
|
44
50
|
- lib/robut/plugin/calc.rb
|
45
51
|
- lib/robut/plugin/echo.rb
|
52
|
+
- lib/robut/plugin/google_images.rb
|
46
53
|
- lib/robut/plugin/help.rb
|
47
54
|
- lib/robut/plugin/later.rb
|
48
55
|
- lib/robut/plugin/lunch.rb
|
49
56
|
- lib/robut/plugin/meme.rb
|
57
|
+
- lib/robut/plugin/pick.rb
|
50
58
|
- lib/robut/plugin/ping.rb
|
51
|
-
- lib/robut/plugin/
|
52
|
-
- lib/robut/plugin/rdio/public/css/rdio.css
|
53
|
-
- lib/robut/plugin/rdio/public/css/style.css
|
54
|
-
- lib/robut/plugin/rdio/public/css/style_after.css
|
55
|
-
- lib/robut/plugin/rdio/public/images/background.png
|
56
|
-
- lib/robut/plugin/rdio/public/images/no-album.png
|
57
|
-
- lib/robut/plugin/rdio/public/index.html
|
58
|
-
- lib/robut/plugin/rdio/public/js/libs/dd_belatedpng.js
|
59
|
-
- lib/robut/plugin/rdio/public/js/libs/jquery-1.5.1.min.js
|
60
|
-
- lib/robut/plugin/rdio/public/js/libs/modernizr-1.7.min.js
|
61
|
-
- lib/robut/plugin/rdio/public/js/rdio.js
|
62
|
-
- lib/robut/plugin/rdio/public/js/script.js
|
63
|
-
- lib/robut/plugin/rdio/server.rb
|
59
|
+
- lib/robut/plugin/quips.rb
|
64
60
|
- lib/robut/plugin/say.rb
|
65
61
|
- lib/robut/plugin/sayings.rb
|
62
|
+
- lib/robut/plugin/stock.rb
|
66
63
|
- lib/robut/plugin/twss.rb
|
67
64
|
- lib/robut/plugin/weather.rb
|
65
|
+
- lib/robut/pm.rb
|
66
|
+
- lib/robut/presence.rb
|
67
|
+
- lib/robut/room.rb
|
68
68
|
- lib/robut/storage.rb
|
69
69
|
- lib/robut/storage/base.rb
|
70
70
|
- lib/robut/storage/hash_store.rb
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- test/fixtures/seattle.xml
|
77
77
|
- test/fixtures/tacoma.xml
|
78
78
|
- test/mocks/connection_mock.rb
|
79
|
+
- test/mocks/presence_mock.rb
|
79
80
|
- test/simplecov_helper.rb
|
80
81
|
- test/test_helper.rb
|
81
82
|
- test/unit/connection_test.rb
|
@@ -84,10 +85,13 @@ files:
|
|
84
85
|
- test/unit/plugin/help_test.rb
|
85
86
|
- test/unit/plugin/later_test.rb
|
86
87
|
- test/unit/plugin/lunch_test.rb
|
88
|
+
- test/unit/plugin/pick_test.rb
|
87
89
|
- test/unit/plugin/ping_test.rb
|
90
|
+
- test/unit/plugin/quips_test.rb
|
88
91
|
- test/unit/plugin/say_test.rb
|
89
92
|
- test/unit/plugin/weather_test.rb
|
90
93
|
- test/unit/plugin_test.rb
|
94
|
+
- test/unit/room_test.rb
|
91
95
|
- test/unit/storage/hash_store_test.rb
|
92
96
|
- test/unit/storage/yaml_store_test.rb
|
93
97
|
- test/unit/storage/yaml_test.yml
|
@@ -105,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
109
|
version: '0'
|
106
110
|
segments:
|
107
111
|
- 0
|
108
|
-
hash:
|
112
|
+
hash: 2804599532514623618
|
109
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
114
|
none: false
|
111
115
|
requirements:
|
@@ -114,10 +118,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
118
|
version: '0'
|
115
119
|
segments:
|
116
120
|
- 0
|
117
|
-
hash:
|
121
|
+
hash: 2804599532514623618
|
118
122
|
requirements: []
|
119
123
|
rubyforge_project: robut
|
120
|
-
rubygems_version: 1.8.
|
124
|
+
rubygems_version: 1.8.24
|
121
125
|
signing_key:
|
122
126
|
specification_version: 3
|
123
127
|
summary: A simple plugin-enabled HipChat bot
|
@@ -127,6 +131,7 @@ test_files:
|
|
127
131
|
- test/fixtures/seattle.xml
|
128
132
|
- test/fixtures/tacoma.xml
|
129
133
|
- test/mocks/connection_mock.rb
|
134
|
+
- test/mocks/presence_mock.rb
|
130
135
|
- test/simplecov_helper.rb
|
131
136
|
- test/test_helper.rb
|
132
137
|
- test/unit/connection_test.rb
|
@@ -135,10 +140,13 @@ test_files:
|
|
135
140
|
- test/unit/plugin/help_test.rb
|
136
141
|
- test/unit/plugin/later_test.rb
|
137
142
|
- test/unit/plugin/lunch_test.rb
|
143
|
+
- test/unit/plugin/pick_test.rb
|
138
144
|
- test/unit/plugin/ping_test.rb
|
145
|
+
- test/unit/plugin/quips_test.rb
|
139
146
|
- test/unit/plugin/say_test.rb
|
140
147
|
- test/unit/plugin/weather_test.rb
|
141
148
|
- test/unit/plugin_test.rb
|
149
|
+
- test/unit/room_test.rb
|
142
150
|
- test/unit/storage/hash_store_test.rb
|
143
151
|
- test/unit/storage/yaml_store_test.rb
|
144
152
|
- test/unit/storage/yaml_test.yml
|
data/lib/robut/plugin/rdio.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'rdio'
|
2
|
-
require 'robut/plugin/rdio/server'
|
3
|
-
|
4
|
-
# A plugin that hooks into Rdio, allowing you to queue songs from
|
5
|
-
# HipChat. +key+ and +secret+ must be set before we can deal with any
|
6
|
-
# Rdio commands. Additionally, you must call +start_server+ in your
|
7
|
-
# Chatfile to start the Rdio web server.
|
8
|
-
class Robut::Plugin::Rdio
|
9
|
-
include Robut::Plugin
|
10
|
-
|
11
|
-
class << self
|
12
|
-
# Your Rdio API Key
|
13
|
-
attr_accessor :key
|
14
|
-
|
15
|
-
# Your Rdio API app secret
|
16
|
-
attr_accessor :secret
|
17
|
-
|
18
|
-
# The port the Rdio web player will run on. Defaults to 4567.
|
19
|
-
attr_accessor :port
|
20
|
-
|
21
|
-
# The host the Rdio web player will run on. Defaults to localhost.
|
22
|
-
attr_accessor :host
|
23
|
-
|
24
|
-
# The playback token for +domain+. If you're accessing Rdio on
|
25
|
-
# localhost, you shouldn't need to change this. Otherwise,
|
26
|
-
# download the rdio-python plugin:
|
27
|
-
#
|
28
|
-
# https://github.com/rdio/rdio-python
|
29
|
-
#
|
30
|
-
# and generate a new token for your domain:
|
31
|
-
#
|
32
|
-
# ./rdio-call --consumer-key=YOUR_CONSUMER_KEY --consumer-secret=YOUR_CONSUMER_SECRET getPlaybackToken domain=YOUR_DOMAIN
|
33
|
-
attr_accessor :token
|
34
|
-
|
35
|
-
# The domain associated with +token+. Defaults to localhost.
|
36
|
-
attr_accessor :domain
|
37
|
-
end
|
38
|
-
|
39
|
-
# Starts a Robut::Plugin::Rdio::Server server for communicating with
|
40
|
-
# the actual Rdio web player. You must call this in the Chatfile if
|
41
|
-
# you plan on using this gem.
|
42
|
-
def self.start_server
|
43
|
-
@server = Thread.new { Server.run! :host => (host || "localhost"), :port => (port || 4567) }
|
44
|
-
Server.token = self.token || "GAlNi78J_____zlyYWs5ZG02N2pkaHlhcWsyOWJtYjkyN2xvY2FsaG9zdEbwl7EHvbylWSWFWYMZwfc="
|
45
|
-
Server.domain = self.domain || "localhost"
|
46
|
-
end
|
47
|
-
|
48
|
-
# Returns a description of how to use this plugin
|
49
|
-
def usage
|
50
|
-
[
|
51
|
-
"#{at_nick} play <song> - queues <song> for playing",
|
52
|
-
"#{at_nick} play album <album> - queues <album> for playing",
|
53
|
-
"#{at_nick} play track <track> - queues <track> for playing"
|
54
|
-
]
|
55
|
-
end
|
56
|
-
|
57
|
-
# Queues songs into the Rdio web player. @nick play search query
|
58
|
-
# will queue the first search result matching 'search query' into
|
59
|
-
# the web player. It can be an artist, album, or song.
|
60
|
-
def handle(time, sender_nick, message)
|
61
|
-
words = words(message)
|
62
|
-
if sent_to_me?(message) && words.first == 'play'
|
63
|
-
results = search(words)
|
64
|
-
result = results.first
|
65
|
-
if result
|
66
|
-
Server.queue << result.key
|
67
|
-
name = result.name
|
68
|
-
name = "#{result.artist_name} - #{name}" if result.respond_to?(:artist_name) && result.artist_name
|
69
|
-
reply("Playing #{name}")
|
70
|
-
else
|
71
|
-
reply("I couldn't find #{query_string} on Rdio.")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
# Searches Rdio for sources matching +words+. If the first word is
|
79
|
-
# 'track', it only searches tracks, same for 'album'. Otherwise,
|
80
|
-
# matches both albums and tracks.
|
81
|
-
def search(words)
|
82
|
-
api = ::Rdio::Api.new(self.class.key, self.class.secret)
|
83
|
-
|
84
|
-
if words[1] == "album"
|
85
|
-
query_string = words[2..-1].join(' ')
|
86
|
-
results = api.search(query_string, "Album")
|
87
|
-
elsif words[1] == "track"
|
88
|
-
query_string = words[2..-1].join(' ')
|
89
|
-
results = api.search(query_string, "Track")
|
90
|
-
else
|
91
|
-
query_string = words[1..-1].join(' ')
|
92
|
-
results = api.search(query_string, "Album,Track")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|