hipbot 0.2.0 → 1.0.0.rc1
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/.gitignore +2 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -0
- data/README.md +28 -20
- data/hipbot.gemspec +2 -2
- data/lib/hipbot.rb +1 -0
- data/lib/hipbot/adapters/hipchat/connection.rb +46 -41
- data/lib/hipbot/adapters/hipchat/hipchat.rb +1 -1
- data/lib/hipbot/adapters/telnet/connection.rb +4 -5
- data/lib/hipbot/bot.rb +61 -48
- data/lib/hipbot/collection.rb +34 -9
- data/lib/hipbot/configuration.rb +15 -7
- data/lib/hipbot/helpers.rb +10 -4
- data/lib/hipbot/logger.rb +0 -4
- data/lib/hipbot/match.rb +48 -0
- data/lib/hipbot/message.rb +13 -13
- data/lib/hipbot/patches/hipchat_client.rb +50 -12
- data/lib/hipbot/plugin.rb +24 -5
- data/lib/hipbot/reactable.rb +27 -42
- data/lib/hipbot/reaction.rb +33 -34
- data/lib/hipbot/response.rb +14 -11
- data/lib/hipbot/room.rb +4 -11
- data/lib/hipbot/user.rb +8 -2
- data/lib/hipbot/version.rb +1 -1
- data/spec/integration/hipbot_spec.rb +96 -68
- data/spec/integration/my_hipbot.rb +104 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/unit/hipbot_spec.rb +45 -34
- data/spec/unit/message_spec.rb +17 -18
- metadata +10 -5
@@ -0,0 +1,104 @@
|
|
1
|
+
module HipbotHelpers
|
2
|
+
def project_name
|
3
|
+
"Project: #{room.name}"
|
4
|
+
end
|
5
|
+
|
6
|
+
def sender_first_name
|
7
|
+
"you are #{message.sender.split[0]}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class AwesomePlugin
|
12
|
+
include Hipbot::Plugin
|
13
|
+
|
14
|
+
desc 'respond awesome - responds with awesome'
|
15
|
+
on /respond awesome/ do
|
16
|
+
reply('awesome responded')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class CoolPlugin
|
21
|
+
include Hipbot::Plugin
|
22
|
+
|
23
|
+
desc 'respond cool - responds with cool'
|
24
|
+
on /respond cool/ do
|
25
|
+
reply('cool responded')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class MyHipbot < Hipbot::Bot
|
30
|
+
configure do |config|
|
31
|
+
config.jid = 'robbot@chat.hipchat.com'
|
32
|
+
config.helpers = HipbotHelpers
|
33
|
+
config.plugins = [CoolPlugin.instance, AwesomePlugin.instance]
|
34
|
+
config.teams = { vip: ['John Doe', 'Jane Doe'] }
|
35
|
+
config.rooms = { project_rooms: ['Project 1', 'Project 2'] }
|
36
|
+
end
|
37
|
+
|
38
|
+
default from: 'Other Guy' do
|
39
|
+
reply('What do you mean, Other Guy?')
|
40
|
+
end
|
41
|
+
|
42
|
+
default do
|
43
|
+
reply("I didn't understand you")
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'greets the user'
|
47
|
+
on /^hello hipbot!$/ do
|
48
|
+
reply('hello!')
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'he already knows that'
|
52
|
+
on /you're (.*), robot/ do |adj|
|
53
|
+
reply("I know I'm #{adj}")
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'says hello'
|
57
|
+
on /hi everyone!/, global: true do
|
58
|
+
reply('hello!')
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'returns project name'
|
62
|
+
on /tell me the project name/ do
|
63
|
+
reply(project_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
desc 'returns sender\'s name'
|
67
|
+
on /tell me my name/ do
|
68
|
+
reply("you are #{sender.first_name}")
|
69
|
+
end
|
70
|
+
|
71
|
+
scope from: 'John Doe' do
|
72
|
+
desc 'does John thing'
|
73
|
+
on /John Doe thing/ do
|
74
|
+
reply('doing John Doe thing')
|
75
|
+
end
|
76
|
+
|
77
|
+
scope room: 'Project 1' do
|
78
|
+
desc 'does John project thing'
|
79
|
+
on /John Doe project thing/ do
|
80
|
+
reply('doing John Doe project thing')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
desc 'deploys project'
|
86
|
+
on /deploy/, room: :project_rooms do
|
87
|
+
reply('deploying')
|
88
|
+
end
|
89
|
+
|
90
|
+
desc 'restarts server'
|
91
|
+
on /restart/, from: :vip do
|
92
|
+
reply('restarting')
|
93
|
+
end
|
94
|
+
|
95
|
+
desc 'does room thing'
|
96
|
+
on /room thing/, room: true do
|
97
|
+
reply('doing room thing')
|
98
|
+
end
|
99
|
+
|
100
|
+
desc 'does private thing'
|
101
|
+
on /private thing/, room: false do
|
102
|
+
reply('doing private thing')
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/hipbot_spec.rb
CHANGED
@@ -2,14 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "a class that inherits", Hipbot::Bot do
|
4
4
|
let(:described_class) { Class.new(Hipbot::Bot) }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
described_class.instance.plugins.clear
|
8
|
+
described_class.instance.setup
|
9
|
+
end
|
5
10
|
subject { described_class.instance }
|
6
11
|
|
7
12
|
context "#on" do
|
8
|
-
let(:sender) { stub_everything(name: 'Tom Smith') }
|
13
|
+
let(:sender) { stub_everything(name: 'Tom Smith', reactions: []) }
|
9
14
|
let(:room) { stub_everything }
|
10
15
|
|
11
16
|
it "should reply to no arguments" do
|
12
|
-
|
17
|
+
described_class.on /^hello there$/ do
|
13
18
|
reply('hi!')
|
14
19
|
end
|
15
20
|
subject.expects(:send_to_room).with(room, 'hi!')
|
@@ -17,7 +22,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
17
22
|
end
|
18
23
|
|
19
24
|
it "should reply with one argument" do
|
20
|
-
|
25
|
+
described_class.on /^you are (.*), robot$/ do |adj|
|
21
26
|
reply("i know i'm #{adj}!")
|
22
27
|
end
|
23
28
|
subject.expects(:send_to_room).with(room, "i know i'm cool!")
|
@@ -25,7 +30,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
25
30
|
end
|
26
31
|
|
27
32
|
it "should reply with multiple arguments" do
|
28
|
-
|
33
|
+
described_class.on /^send "(.*)" to (.*@.*)$/ do |message, recipient|
|
29
34
|
reply("sent \"#{message}\" to #{recipient}")
|
30
35
|
end
|
31
36
|
subject.expects(:send_to_room).with(room, 'sent "hello!" to robot@robots.org')
|
@@ -41,15 +46,15 @@ describe "a class that inherits", Hipbot::Bot do
|
|
41
46
|
end
|
42
47
|
|
43
48
|
it "should choose first option when multiple options match" do
|
44
|
-
|
45
|
-
|
49
|
+
described_class.on /hello there/ do reply('hello there') end
|
50
|
+
described_class.on /hello (.*)/ do reply('hello') end
|
46
51
|
subject.expects(:send_to_room).with(room, 'hello there')
|
47
52
|
subject.react(sender, room, '@robot hello there')
|
48
53
|
end
|
49
54
|
|
50
55
|
context "multiple regexps" do
|
51
56
|
before do
|
52
|
-
|
57
|
+
described_class.on /hello (.*)/, /good morning (.*)/, /guten tag (.*)/ do |name|
|
53
58
|
reply("hello #{name}")
|
54
59
|
end
|
55
60
|
end
|
@@ -72,7 +77,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
72
77
|
|
73
78
|
context "global messages" do
|
74
79
|
it "should reply if callback is global" do
|
75
|
-
|
80
|
+
described_class.on /^you are (.*)$/, global: true do |adj|
|
76
81
|
reply("i know i'm #{adj}!")
|
77
82
|
end
|
78
83
|
subject.expects(:send_to_room).with(room, "i know i'm cool!")
|
@@ -80,7 +85,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
80
85
|
end
|
81
86
|
|
82
87
|
it "should not reply if callback not global" do
|
83
|
-
|
88
|
+
described_class.on /^you are (.*)$/ do |adj|
|
84
89
|
reply("i know i'm #{adj}!")
|
85
90
|
end
|
86
91
|
subject.expects(:send_to_room).never
|
@@ -89,30 +94,34 @@ describe "a class that inherits", Hipbot::Bot do
|
|
89
94
|
end
|
90
95
|
|
91
96
|
context "messages from particular sender" do
|
92
|
-
let(:other_user) { stub(name: "John") }
|
97
|
+
let(:other_user) { stub(name: "John", reactions: []) }
|
98
|
+
|
93
99
|
it "should reply" do
|
94
|
-
|
100
|
+
described_class.on /wazzup\?/, from: sender.name do
|
95
101
|
reply('Wazzup, Tom?')
|
96
102
|
end
|
97
103
|
subject.expects(:send_to_room).with(room, 'Wazzup, Tom?')
|
98
104
|
subject.react(sender, room, '@robot wazzup?')
|
99
105
|
end
|
106
|
+
|
100
107
|
it "should reply if sender acceptable" do
|
101
|
-
|
108
|
+
described_class.on /wazzup\?/, from: [stub, sender.name] do
|
102
109
|
reply('wazzup, tom?')
|
103
110
|
end
|
104
111
|
subject.expects(:send_to_room).with(room, 'wazzup, tom?')
|
105
112
|
subject.react(sender, room, '@robot wazzup?')
|
106
113
|
end
|
114
|
+
|
107
115
|
it "should not reply if sender unacceptable" do
|
108
|
-
|
116
|
+
described_class.on /wazzup\?/, from: sender.name do
|
109
117
|
reply('wazzup, tom?')
|
110
118
|
end
|
111
119
|
subject.expects(:send_to_room).never
|
112
120
|
subject.react(other_user, room, '@robot wazzup?')
|
113
121
|
end
|
122
|
+
|
114
123
|
it "should not reply if sender does not match" do
|
115
|
-
|
124
|
+
described_class.on /wazzup\?/, from: [sender.name] do
|
116
125
|
reply('wazzup, tom?')
|
117
126
|
end
|
118
127
|
subject.expects(:send_to_room).never
|
@@ -123,29 +132,33 @@ describe "a class that inherits", Hipbot::Bot do
|
|
123
132
|
context "messages in particular room" do
|
124
133
|
let(:room) { stub(:name => 'room') }
|
125
134
|
let(:other_room) { stub(:name => 'other_room') }
|
135
|
+
|
126
136
|
it "should reply" do
|
127
|
-
|
137
|
+
described_class.on /wazzup\?/, room: 'room' do
|
128
138
|
reply('Wazzup, Tom?')
|
129
139
|
end
|
130
140
|
subject.expects(:send_to_room).with(room, 'Wazzup, Tom?')
|
131
141
|
subject.react(sender, room, '@robot wazzup?')
|
132
142
|
end
|
143
|
+
|
133
144
|
it "should reply if room acceptable" do
|
134
|
-
|
145
|
+
described_class.on /wazzup\?/, room: ['other_room', 'room'] do
|
135
146
|
reply('wazzup, tom?')
|
136
147
|
end
|
137
148
|
subject.expects(:send_to_room).with(room, 'wazzup, tom?')
|
138
149
|
subject.react(sender, room, '@robot wazzup?')
|
139
150
|
end
|
151
|
+
|
140
152
|
it "should not reply if room unacceptable" do
|
141
|
-
|
153
|
+
described_class.on /wazzup\?/, room: 'room' do
|
142
154
|
reply('wazzup, tom?')
|
143
155
|
end
|
144
156
|
subject.expects(:send_to_room).never
|
145
157
|
subject.react(sender, other_room, '@robot wazzup?')
|
146
158
|
end
|
159
|
+
|
147
160
|
it "should not reply if room does not match" do
|
148
|
-
|
161
|
+
described_class.on /wazzup\?/, room: ['other_room'] do
|
149
162
|
reply('wazzup, tom?')
|
150
163
|
end
|
151
164
|
subject.expects(:send_to_room).never
|
@@ -154,10 +167,10 @@ describe "a class that inherits", Hipbot::Bot do
|
|
154
167
|
end
|
155
168
|
|
156
169
|
context "response helper" do
|
157
|
-
let(:user){ stub(name: 'Tom Smith', first_name: 'Tom') }
|
170
|
+
let(:user){ stub(name: 'Tom Smith', first_name: 'Tom', reactions: []) }
|
158
171
|
|
159
172
|
it "message" do
|
160
|
-
|
173
|
+
described_class.on /.*/ do
|
161
174
|
reply("you said: #{message.body}")
|
162
175
|
end
|
163
176
|
subject.expects(:send_to_room).with(room, "you said: hello")
|
@@ -165,7 +178,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
165
178
|
end
|
166
179
|
|
167
180
|
it "sender" do
|
168
|
-
|
181
|
+
described_class.on /.*/ do
|
169
182
|
reply("you are: #{sender.name}")
|
170
183
|
end
|
171
184
|
subject.expects(:send_to_room).with(room, "you are: Tom Smith")
|
@@ -173,7 +186,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
173
186
|
end
|
174
187
|
|
175
188
|
it "recipients" do
|
176
|
-
|
189
|
+
described_class.on /.*/ do
|
177
190
|
reply("recipients: #{message.recipients.join(', ')}")
|
178
191
|
end
|
179
192
|
subject.expects(:send_to_room).with(room, "recipients: robot, dave")
|
@@ -181,7 +194,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
181
194
|
end
|
182
195
|
|
183
196
|
it "sender name" do
|
184
|
-
|
197
|
+
described_class.on /.*/ do
|
185
198
|
reply(message.sender.first_name)
|
186
199
|
end
|
187
200
|
subject.expects(:send_to_room).with(room, 'Tom')
|
@@ -189,7 +202,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
189
202
|
end
|
190
203
|
|
191
204
|
it "mentions" do
|
192
|
-
|
205
|
+
described_class.on /.*/ do
|
193
206
|
reply(message.mentions.join(' '))
|
194
207
|
end
|
195
208
|
subject.expects(:send_to_room).with(room, 'dave rachel')
|
@@ -198,8 +211,10 @@ describe "a class that inherits", Hipbot::Bot do
|
|
198
211
|
end
|
199
212
|
|
200
213
|
context "plugins" do
|
201
|
-
let(:plugin) {
|
202
|
-
Class.new
|
214
|
+
let!(:plugin) {
|
215
|
+
Class.new do
|
216
|
+
include Hipbot::Plugin
|
217
|
+
|
203
218
|
on /plugin respond/ do
|
204
219
|
reply("plugin ack")
|
205
220
|
end
|
@@ -218,10 +233,6 @@ describe "a class that inherits", Hipbot::Bot do
|
|
218
233
|
end
|
219
234
|
}
|
220
235
|
|
221
|
-
before do
|
222
|
-
subject.configuration.plugins = [ plugin ]
|
223
|
-
end
|
224
|
-
|
225
236
|
it "should respond to reaction defined in plugin" do
|
226
237
|
subject.expects(:send_to_room).with(room, 'plugin ack')
|
227
238
|
subject.react(sender, room, '@robot plugin respond')
|
@@ -232,15 +243,15 @@ describe "a class that inherits", Hipbot::Bot do
|
|
232
243
|
subject.react(sender, room, '@robot blahblah')
|
233
244
|
end
|
234
245
|
|
235
|
-
it "
|
246
|
+
it "shouldn't respond to default defined in bot if plugins define own defaults" do
|
236
247
|
described_class.default do
|
237
|
-
reply(
|
248
|
+
reply('bot default')
|
238
249
|
end
|
239
|
-
subject.expects(:send_to_room).with(room, '
|
250
|
+
subject.expects(:send_to_room).with(room, 'plugin default')
|
240
251
|
subject.react(sender, room, '@robot blahblah')
|
241
252
|
end
|
242
253
|
|
243
|
-
it
|
254
|
+
it 'should have access to #plugin inside reaction' do
|
244
255
|
subject.expects(:send_to_room).with(room, 'some method')
|
245
256
|
subject.react(sender, room, '@robot plugin method')
|
246
257
|
end
|
data/spec/unit/message_spec.rb
CHANGED
@@ -3,57 +3,56 @@ require 'spec_helper'
|
|
3
3
|
describe Hipbot::Message do
|
4
4
|
subject { Hipbot::Message }
|
5
5
|
let(:sender) { stub }
|
6
|
+
let(:room) { stub }
|
7
|
+
before(:all) do
|
8
|
+
Hipbot.bot = Hipbot::Bot.instance
|
9
|
+
end
|
6
10
|
|
7
11
|
it "should have a body" do
|
8
|
-
message = subject.new('this is a message', sender)
|
12
|
+
message = subject.new('this is a message', room, sender)
|
9
13
|
message.body.should == 'this is a message'
|
10
14
|
end
|
11
15
|
|
12
16
|
it "should have a sender" do
|
13
|
-
message = subject.new('this is a message', sender)
|
17
|
+
message = subject.new('this is a message', room, sender)
|
14
18
|
message.sender.should == sender
|
15
19
|
end
|
16
20
|
|
17
21
|
it "should have no recipients" do
|
18
|
-
message = subject.new('this is a message', sender)
|
22
|
+
message = subject.new('this is a message', room, sender)
|
19
23
|
message.recipients.should be_empty
|
20
24
|
end
|
21
25
|
|
22
26
|
it "should have one recipient" do
|
23
|
-
message = subject.new('this is a message for @tom', sender)
|
27
|
+
message = subject.new('this is a message for @tom', room, sender)
|
24
28
|
message.recipients.should include('tom')
|
25
29
|
end
|
26
30
|
|
27
|
-
it "should have one long recipient" do
|
28
|
-
message = subject.new('message for @"tom jones", deal with it', sender)
|
29
|
-
message.recipients.should include('tom jones')
|
30
|
-
end
|
31
|
-
|
32
31
|
it "should have two recipients" do
|
33
|
-
message = subject.new('@dave, this is a message for @tom', sender)
|
32
|
+
message = subject.new('@dave, this is a message for @tom', room, sender)
|
34
33
|
message.recipients.should include('tom')
|
35
34
|
message.recipients.should include('dave')
|
36
35
|
end
|
37
36
|
|
38
37
|
it "should strip primary recipient from message" do
|
39
|
-
message = subject.new('@dave this is a message for @tom', sender)
|
38
|
+
message = subject.new('@dave this is a message for @tom', room, sender)
|
40
39
|
message.body.should == 'this is a message for @tom'
|
41
40
|
end
|
42
41
|
|
43
42
|
it "should strip primary recipient from message with commma" do
|
44
|
-
message = subject.new('@dave, this is a message for @tom', sender)
|
43
|
+
message = subject.new('@dave, this is a message for @tom', room, sender)
|
45
44
|
message.body.should == 'this is a message for @tom'
|
46
45
|
end
|
47
46
|
|
48
47
|
it "should be for bot" do
|
49
|
-
|
50
|
-
message = subject.new('hello @robot!', sender)
|
51
|
-
message.for?(
|
48
|
+
user = stub(:mention => 'robot')
|
49
|
+
message = subject.new('hello @robot!', room, sender)
|
50
|
+
message.for?(user).should be_true
|
52
51
|
end
|
53
52
|
|
54
53
|
it "should not be for bot" do
|
55
|
-
|
56
|
-
message = subject.new('hello @tom!', sender)
|
57
|
-
message.for?(
|
54
|
+
user = stub(:mention => 'robot')
|
55
|
+
message = subject.new('hello @tom!', room, sender)
|
56
|
+
message.for?(user).should be_false
|
58
57
|
end
|
59
58
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hipbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
+
- Bartosz Kopiński
|
8
9
|
- Tomasz Pewiński
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: daemons
|
@@ -157,6 +158,7 @@ dependencies:
|
|
157
158
|
version: 0.13.3
|
158
159
|
description: Hipbot is a bot for HipChat, written in ruby & eventmachine.
|
159
160
|
email:
|
161
|
+
- bartosz.kopinski@netguru.pl
|
160
162
|
- pewniak747@gmail.com
|
161
163
|
executables:
|
162
164
|
- hipbot
|
@@ -186,6 +188,7 @@ files:
|
|
186
188
|
- lib/hipbot/configuration.rb
|
187
189
|
- lib/hipbot/helpers.rb
|
188
190
|
- lib/hipbot/logger.rb
|
191
|
+
- lib/hipbot/match.rb
|
189
192
|
- lib/hipbot/message.rb
|
190
193
|
- lib/hipbot/patches/encoding.rb
|
191
194
|
- lib/hipbot/patches/hipchat_client.rb
|
@@ -197,6 +200,7 @@ files:
|
|
197
200
|
- lib/hipbot/user.rb
|
198
201
|
- lib/hipbot/version.rb
|
199
202
|
- spec/integration/hipbot_spec.rb
|
203
|
+
- spec/integration/my_hipbot.rb
|
200
204
|
- spec/spec_helper.rb
|
201
205
|
- spec/unit/hipbot_spec.rb
|
202
206
|
- spec/unit/message_spec.rb
|
@@ -215,9 +219,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
215
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
220
|
none: false
|
217
221
|
requirements:
|
218
|
-
- - ! '
|
222
|
+
- - ! '>'
|
219
223
|
- !ruby/object:Gem::Version
|
220
|
-
version:
|
224
|
+
version: 1.3.1
|
221
225
|
requirements: []
|
222
226
|
rubyforge_project:
|
223
227
|
rubygems_version: 1.8.23
|
@@ -226,6 +230,7 @@ specification_version: 3
|
|
226
230
|
summary: Hipbot is a bot for HipChat, written in ruby & eventmachine.
|
227
231
|
test_files:
|
228
232
|
- spec/integration/hipbot_spec.rb
|
233
|
+
- spec/integration/my_hipbot.rb
|
229
234
|
- spec/spec_helper.rb
|
230
235
|
- spec/unit/hipbot_spec.rb
|
231
236
|
- spec/unit/message_spec.rb
|