hipbot 1.0.0.rc2 → 1.0.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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +6 -0
  4. data/Gemfile +1 -2
  5. data/README.md +482 -88
  6. data/Rakefile +1 -1
  7. data/bin/hipbot +4 -4
  8. data/hipbot.gemspec +9 -9
  9. data/lib/hipbot.rb +28 -11
  10. data/lib/hipbot/adapter.rb +80 -0
  11. data/lib/hipbot/adapters/hipchat.rb +53 -0
  12. data/lib/hipbot/adapters/hipchat/initializer.rb +83 -0
  13. data/lib/hipbot/adapters/shell.rb +37 -0
  14. data/lib/hipbot/adapters/telnet.rb +41 -0
  15. data/lib/hipbot/bot.rb +15 -52
  16. data/lib/hipbot/cache.rb +23 -0
  17. data/lib/hipbot/callbacks/base.rb +15 -0
  18. data/lib/hipbot/callbacks/invite.rb +11 -0
  19. data/lib/hipbot/callbacks/lobby_presence.rb +13 -0
  20. data/lib/hipbot/callbacks/message.rb +11 -0
  21. data/lib/hipbot/callbacks/presence.rb +17 -0
  22. data/lib/hipbot/callbacks/private_message.rb +12 -0
  23. data/lib/hipbot/callbacks/room_message.rb +21 -0
  24. data/lib/hipbot/callbacks/room_presence.rb +28 -0
  25. data/lib/hipbot/configurable.rb +22 -0
  26. data/lib/hipbot/configuration.rb +9 -3
  27. data/lib/hipbot/helpers.rb +4 -40
  28. data/lib/hipbot/http.rb +65 -0
  29. data/lib/hipbot/match.rb +21 -9
  30. data/lib/hipbot/matchable.rb +38 -0
  31. data/lib/hipbot/message.rb +24 -9
  32. data/lib/hipbot/plugin.rb +3 -3
  33. data/lib/hipbot/reactable.rb +14 -21
  34. data/lib/hipbot/reaction.rb +27 -15
  35. data/lib/hipbot/reaction_factory.rb +38 -0
  36. data/lib/hipbot/response.rb +18 -10
  37. data/lib/hipbot/room.rb +34 -2
  38. data/lib/hipbot/storages/base.rb +78 -0
  39. data/lib/hipbot/storages/hash.rb +89 -0
  40. data/lib/hipbot/storages/mongoid.rb +18 -0
  41. data/lib/hipbot/user.rb +8 -2
  42. data/lib/hipbot/version.rb +1 -1
  43. data/spec/integration/my_hipbot.rb +24 -4
  44. data/spec/integration/{hipbot_spec.rb → my_hipbot_spec.rb} +41 -23
  45. data/spec/spec_helper.rb +14 -2
  46. data/spec/unit/adapters/hipchat_spec.rb +5 -0
  47. data/spec/unit/{hipbot_spec.rb → bot_spec.rb} +13 -12
  48. data/spec/unit/match_spec.rb +148 -0
  49. data/spec/unit/message_spec.rb +14 -7
  50. data/spec/unit/reaction_factory_spec.rb +54 -0
  51. data/spec/unit/reaction_spec.rb +99 -0
  52. data/spec/unit/storages/hash_spec.rb +75 -0
  53. data/spec/unit/user_spec.rb +0 -2
  54. metadata +64 -54
  55. data/Gemfile.lock +0 -90
  56. data/examples/cleverbot.rb +0 -23
  57. data/examples/google_images.rb +0 -35
  58. data/lib/hipbot/adapters/hipchat/connection.rb +0 -166
  59. data/lib/hipbot/adapters/hipchat/hipchat.rb +0 -13
  60. data/lib/hipbot/adapters/telnet/connection.rb +0 -17
  61. data/lib/hipbot/adapters/telnet/telnet.rb +0 -14
  62. data/lib/hipbot/collection.rb +0 -72
  63. data/lib/hipbot/patches/hipchat_client.rb +0 -230
@@ -4,9 +4,9 @@ describe Hipbot::Message do
4
4
  subject { Hipbot::Message }
5
5
  let(:sender) { stub }
6
6
  let(:room) { stub }
7
- before(:all) do
8
- Hipbot.bot = Hipbot::Bot.instance
9
- end
7
+ before(:all) {
8
+ Hipbot::Bot.instance.setup
9
+ }
10
10
 
11
11
  it "should have a body" do
12
12
  message = subject.new('this is a message', room, sender)
@@ -34,25 +34,32 @@ describe Hipbot::Message do
34
34
  message.recipients.should include('dave')
35
35
  end
36
36
 
37
- it "should strip primary recipient from message" do
37
+ it "should strip bot mention from message" do
38
+ Hipbot.configuration.user = stub(mention: 'dave')
38
39
  message = subject.new('@dave this is a message for @tom', room, sender)
39
40
  message.body.should == 'this is a message for @tom'
40
41
  end
41
42
 
42
- it "should strip primary recipient from message with commma" do
43
+ it "should strip bot mention from message with commma" do
44
+ Hipbot.configuration.user = stub(mention: 'dave')
43
45
  message = subject.new('@dave, this is a message for @tom', room, sender)
44
46
  message.body.should == 'this is a message for @tom'
45
47
  end
46
48
 
47
49
  it "should be for bot" do
48
- user = stub(:mention => 'robot')
50
+ user = stub(mention: 'robot')
49
51
  message = subject.new('hello @robot!', room, sender)
50
52
  message.for?(user).should be_true
51
53
  end
52
54
 
53
55
  it "should not be for bot" do
54
- user = stub(:mention => 'robot')
56
+ user = stub(mention: 'robot')
55
57
  message = subject.new('hello @tom!', room, sender)
56
58
  message.for?(user).should be_false
57
59
  end
60
+
61
+ it 'knows its recipients' do
62
+ message = subject.new('@tom, @dave: @mike')
63
+ message.recipients.should == ['tom', 'dave', 'mike']
64
+ end
58
65
  end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hipbot::ReactionFactory do
4
+ subject { described_class.new(stub) }
5
+
6
+ let(:params) { [] }
7
+ let(:block) { stub }
8
+
9
+ let(:options_stack) { [subject.get_reaction_options(params)] }
10
+ let(:reaction) { subject.build(options_stack, block) }
11
+
12
+ describe "taking a regexp" do
13
+ let(:params) { [/.*/] }
14
+
15
+ it "builds a reaction with regexp" do
16
+ expect(reaction.regexps).to eq([/.*/i])
17
+ end
18
+
19
+ describe "with additional options" do
20
+ let(:params) { [/.*/, { from: 'wat' }] }
21
+
22
+ it "builds a reaction with proper options" do
23
+ expect(reaction.options).to eq(from: 'wat', regexps: [/.*/], desc: nil)
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "taking multiple regexps and options" do
29
+ let(:params) { [/.*/, /wat/, { from: 'wat' }] }
30
+
31
+ it "builds a reaction with proper options" do
32
+ expect(reaction.options).to eq(from: 'wat', regexps: [/.*/, /wat/], desc: nil)
33
+ end
34
+ end
35
+
36
+ describe "setting description" do
37
+ before do
38
+ subject.description('woot')
39
+ end
40
+
41
+ it "builds reaction with proper description" do
42
+ expect(reaction.desc).to eq('woot')
43
+ end
44
+
45
+ it "resets description after first built reaction" do
46
+ subject.build(params, block)
47
+ expect(reaction.desc).to be_nil
48
+ end
49
+ end
50
+
51
+ it "applies optional scope params as default" do
52
+ expect(subject.build([{ from: 'dave' }], block).options[:from]).to eq('dave')
53
+ end
54
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hipbot::Reaction do
4
+ subject { Hipbot::Reaction }
5
+
6
+ context 'instance' do
7
+ let(:options){ {} }
8
+ let(:reaction){ subject.new(@plugin, options, @block) }
9
+
10
+ it '#in_any_room?' do
11
+ reaction.in_any_room?.should be_false
12
+ options[:room] = true
13
+ reaction.in_any_room?.should be_true
14
+ end
15
+
16
+ it '#to_anything?' do
17
+ reaction.to_anything?.should be_true
18
+ reaction.options[:regexps] = nil
19
+ reaction.to_anything?.should be_true
20
+ end
21
+
22
+ it '#from_anywhere?' do
23
+ reaction.from_anywhere?.should be_true
24
+ reaction.options[:room] = nil
25
+ reaction.from_anywhere?.should be_true
26
+ end
27
+
28
+ it '#condition' do
29
+ reaction.condition.call.should be_true
30
+ reaction.options[:if] = proc{ false }
31
+ reaction.condition.call.should be_false
32
+ end
33
+
34
+ it '#delete' do
35
+ @plugin = stub(reactions: [reaction])
36
+ reaction.plugin = @plugin
37
+ reaction.delete
38
+ @plugin.reactions.should be_empty
39
+ end
40
+
41
+ it '#desc' do
42
+ reaction.desc.should be_nil
43
+ reaction.options[:desc] = 'description'
44
+ reaction.desc.should == 'description'
45
+ end
46
+
47
+ it '#from_all?' do
48
+ reaction.from_all?.should be_true
49
+ reaction.options[:room] = nil
50
+ reaction.from_all?.should be_true
51
+ end
52
+
53
+ it '#global?' do
54
+ reaction.global?.should be_false
55
+ reaction.options = { global: true }
56
+ reaction.global?.should be_true
57
+ end
58
+
59
+ it '#plugin_name' do
60
+ @plugin = (MyPlugins = Class.new)
61
+ reaction.plugin_name.should == 'MyPlugins'
62
+ end
63
+
64
+ it '#match_with' do
65
+ message = stub
66
+ reaction.match_with(message).should == Hipbot::Match.new(reaction, message)
67
+ end
68
+
69
+ it '#to_private_message?' do
70
+ reaction.to_private_message?.should be_false
71
+ reaction.options[:room] = false
72
+ reaction.to_private_message?.should be_true
73
+ end
74
+
75
+ it '#regexps' do
76
+ options[:regexps] = [/^sample regexp$/i, /^another one$/]
77
+ reaction.regexps.should == [/^sample regexp$/i, /^another one$/i]
78
+ end
79
+
80
+ it '#readable_command' do
81
+ options[:regexps] = [/^sample regexp$/i, /^another one$/]
82
+ reaction.readable_command.should == 'sample regexp or another one'
83
+ end
84
+
85
+ it '#rooms' do
86
+ rooms = ['Room 1', 'Room 2']
87
+ Hipbot.bot = stub(rooms: { special_rooms: rooms })
88
+ options[:room] = [:special_rooms, 'Room 3']
89
+ reaction.rooms.should == [*rooms, 'Room 3']
90
+ end
91
+
92
+ it '#users' do
93
+ users = ['User 1', 'User 2']
94
+ Hipbot.bot = stub(teams: { special_users: users })
95
+ options[:from] = [:special_users, 'User 3']
96
+ reaction.users.should == [*users, 'User 3']
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hipbot::Storages::Hash do
4
+ let(:collection) { Class.new{ include Hipbot::Storages::Hash } }
5
+ let(:item) { collection.find(1) }
6
+ before do
7
+ @item = collection.create(id: 1, name: 'item', something: 'value')
8
+ end
9
+
10
+ context 'collection' do
11
+ context '#create' do
12
+ it 'creates new item' do
13
+ collection.all.count.should == 1
14
+ end
15
+
16
+ it 'saves the id' do
17
+ @item.id.should == 1
18
+ end
19
+
20
+ it 'saves the attributes' do
21
+ @item.attributes[:something].should == 'value'
22
+ end
23
+ end
24
+
25
+ context 'lookups' do
26
+ it 'finds by id' do
27
+ item.should == @item
28
+ end
29
+
30
+ it 'finds by params' do
31
+ collection.find_by(name: 'item') == @item
32
+ collection.find_by(name: 'item', id: 1) == @item
33
+ collection.find_by(name: 'item', id: 1, something: 'value') == @item
34
+ end
35
+
36
+ it 'finds all by params' do
37
+ @item2 = collection.create(id: 2, name: 'item 2', something: 'value')
38
+ collection.where(something: 'value').should == [@item, @item2]
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'item' do
44
+ it 'aliases :name as :to_s' do
45
+ item.to_s.should == item.name
46
+ end
47
+
48
+ context 'updating attributes on lookup result' do
49
+ before do
50
+ item.update_attributes(name: 'item 2', something: 'value 2')
51
+ end
52
+
53
+ it 'changes the attributes' do
54
+ @item.name.should == 'item 2'
55
+ @item.attributes[:something].should == 'value 2'
56
+ end
57
+ end
58
+
59
+ context 'updating attributes on created object' do
60
+ before do
61
+ @item.update_attributes(name: 'item 3', something: 'value 3')
62
+ end
63
+
64
+ it 'changes the attributes' do
65
+ item.name.should == 'item 3'
66
+ item.attributes[:something].should == 'value 3'
67
+ end
68
+ end
69
+
70
+ it 'destroys itself' do
71
+ item.destroy
72
+ collection.all.should be_empty
73
+ end
74
+ end
75
+ end
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Hipbot::User do
4
4
  subject { described_class.new(id: '1234', name: 'test bot', mention: 'testbotmention') }
5
- before { described_class.send(:include, Hipbot::Collection) }
6
5
 
7
6
  its(:first_name) { should == 'test' }
8
7
  its(:mention) { should == 'testbotmention' }
@@ -11,5 +10,4 @@ describe Hipbot::User do
11
10
  subject { described_class.new(id: '1234', name: 'test bot name') }
12
11
  its(:mention) { should == 'testbotname' }
13
12
  end
14
-
15
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hipbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Kopiński
@@ -9,92 +9,78 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-03 00:00:00.000000000 Z
12
+ date: 2013-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: daemons
15
+ name: xmpp4r-hipchat
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - '>='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.1.8
20
+ version: 0.0.3
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - '>='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.1.8
27
+ version: 0.0.3
28
28
  - !ruby/object:Gem::Dependency
29
- name: activesupport
29
+ name: daemons
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
- version: 3.2.12
34
+ version: 1.1.8
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
- version: 3.2.12
41
+ version: 1.1.8
42
42
  - !ruby/object:Gem::Dependency
43
- name: i18n
43
+ name: activesupport
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
- version: 0.6.0
48
+ version: 3.2.12
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - '>='
54
54
  - !ruby/object:Gem::Version
55
- version: 0.6.0
55
+ version: 3.2.12
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: eventmachine
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: 1.0.3
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: 1.0.3
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: em-http-request
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ~>
74
+ - - '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: 1.0.3
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.0.3
84
- - !ruby/object:Gem::Dependency
85
- name: xmpp4r
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ~>
89
- - !ruby/object:Gem::Version
90
- version: '0.5'
91
- type: :runtime
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ~>
96
- - !ruby/object:Gem::Version
97
- version: '0.5'
98
84
  - !ruby/object:Gem::Dependency
99
85
  name: rspec
100
86
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +123,7 @@ dependencies:
137
123
  - - ~>
138
124
  - !ruby/object:Gem::Version
139
125
  version: 0.13.3
140
- description: Hipbot is a bot for HipChat, written in ruby & eventmachine.
126
+ description: Hipbot is a XMPP bot for HipChat, written in Ruby with EventMachine.
141
127
  email:
142
128
  - bartosz.kopinski@netguru.pl
143
129
  - pewniak747@gmail.com
@@ -150,44 +136,62 @@ files:
150
136
  - .rspec
151
137
  - .travis.yml
152
138
  - Gemfile
153
- - Gemfile.lock
154
139
  - Guardfile
155
140
  - LICENSE
156
141
  - README.md
157
142
  - Rakefile
158
143
  - bin/hipbot
159
- - examples/cleverbot.rb
160
- - examples/google_images.rb
161
144
  - hipbot.gemspec
162
145
  - lib/hipbot.rb
163
- - lib/hipbot/adapters/hipchat/connection.rb
164
- - lib/hipbot/adapters/hipchat/hipchat.rb
165
- - lib/hipbot/adapters/telnet/connection.rb
166
- - lib/hipbot/adapters/telnet/telnet.rb
146
+ - lib/hipbot/adapter.rb
147
+ - lib/hipbot/adapters/hipchat.rb
148
+ - lib/hipbot/adapters/hipchat/initializer.rb
149
+ - lib/hipbot/adapters/shell.rb
150
+ - lib/hipbot/adapters/telnet.rb
167
151
  - lib/hipbot/bot.rb
168
- - lib/hipbot/collection.rb
152
+ - lib/hipbot/cache.rb
153
+ - lib/hipbot/callbacks/base.rb
154
+ - lib/hipbot/callbacks/invite.rb
155
+ - lib/hipbot/callbacks/lobby_presence.rb
156
+ - lib/hipbot/callbacks/message.rb
157
+ - lib/hipbot/callbacks/presence.rb
158
+ - lib/hipbot/callbacks/private_message.rb
159
+ - lib/hipbot/callbacks/room_message.rb
160
+ - lib/hipbot/callbacks/room_presence.rb
161
+ - lib/hipbot/configurable.rb
169
162
  - lib/hipbot/configuration.rb
170
163
  - lib/hipbot/helpers.rb
164
+ - lib/hipbot/http.rb
171
165
  - lib/hipbot/logger.rb
172
166
  - lib/hipbot/match.rb
167
+ - lib/hipbot/matchable.rb
173
168
  - lib/hipbot/message.rb
174
169
  - lib/hipbot/patches/encoding.rb
175
- - lib/hipbot/patches/hipchat_client.rb
176
170
  - lib/hipbot/plugin.rb
177
171
  - lib/hipbot/reactable.rb
178
172
  - lib/hipbot/reaction.rb
173
+ - lib/hipbot/reaction_factory.rb
179
174
  - lib/hipbot/response.rb
180
175
  - lib/hipbot/room.rb
176
+ - lib/hipbot/storages/base.rb
177
+ - lib/hipbot/storages/hash.rb
178
+ - lib/hipbot/storages/mongoid.rb
181
179
  - lib/hipbot/user.rb
182
180
  - lib/hipbot/version.rb
183
- - spec/integration/hipbot_spec.rb
184
181
  - spec/integration/my_hipbot.rb
182
+ - spec/integration/my_hipbot_spec.rb
185
183
  - spec/spec_helper.rb
186
- - spec/unit/hipbot_spec.rb
184
+ - spec/unit/adapters/hipchat_spec.rb
185
+ - spec/unit/bot_spec.rb
186
+ - spec/unit/match_spec.rb
187
187
  - spec/unit/message_spec.rb
188
+ - spec/unit/reaction_factory_spec.rb
189
+ - spec/unit/reaction_spec.rb
190
+ - spec/unit/storages/hash_spec.rb
188
191
  - spec/unit/user_spec.rb
189
192
  homepage: http://github.com/pewniak747/hipbot
190
- licenses: []
193
+ licenses:
194
+ - MIT
191
195
  metadata: {}
192
196
  post_install_message:
193
197
  rdoc_options: []
@@ -200,19 +204,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
204
  version: '0'
201
205
  required_rubygems_version: !ruby/object:Gem::Requirement
202
206
  requirements:
203
- - - '>'
207
+ - - '>='
204
208
  - !ruby/object:Gem::Version
205
- version: 1.3.1
209
+ version: '0'
206
210
  requirements: []
207
211
  rubyforge_project:
208
- rubygems_version: 2.0.3
212
+ rubygems_version: 2.1.11
209
213
  signing_key:
210
214
  specification_version: 4
211
- summary: Hipbot is a bot for HipChat, written in ruby & eventmachine.
215
+ summary: Hipbot is a XMPP bot for HipChat, written in Ruby with EventMachine.
212
216
  test_files:
213
- - spec/integration/hipbot_spec.rb
214
217
  - spec/integration/my_hipbot.rb
218
+ - spec/integration/my_hipbot_spec.rb
215
219
  - spec/spec_helper.rb
216
- - spec/unit/hipbot_spec.rb
220
+ - spec/unit/adapters/hipchat_spec.rb
221
+ - spec/unit/bot_spec.rb
222
+ - spec/unit/match_spec.rb
217
223
  - spec/unit/message_spec.rb
224
+ - spec/unit/reaction_factory_spec.rb
225
+ - spec/unit/reaction_spec.rb
226
+ - spec/unit/storages/hash_spec.rb
218
227
  - spec/unit/user_spec.rb
228
+ has_rdoc: