lita-tipbot 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lita/handlers/tipbot.rb +9 -2
- data/lita-tipbot.gemspec +1 -1
- data/spec/lita/handlers/tipbot_spec.rb +31 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 859a431c9a77933c570e155163949d68dc414008
|
4
|
+
data.tar.gz: e1809b39eb9360a88515c3efab0e84f511bda247
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9617ea735081584d93662a9242e10befd1d8d44a37019aefbbe976b25647088ce9c927edb75084ff00e179c20cf5c84bffd3566802ceff522ddfced509358e03
|
7
|
+
data.tar.gz: be2237048c0ded054733f7cd0644fde59cd40fb033cf84892d85f8f19d2b753201e7f9b310c57d15a246985723d73f58db16d927c04fbbfce1e3cfe8c2c6a8f0
|
data/lib/lita/handlers/tipbot.rb
CHANGED
@@ -180,6 +180,9 @@ module Lita
|
|
180
180
|
users = active_room_members room_jid
|
181
181
|
|
182
182
|
users.shuffle.each do |user|
|
183
|
+
# skip tipper
|
184
|
+
next if user['mention_name'] == response.user.mention_name
|
185
|
+
|
183
186
|
log.info "tipping #{user['email']}"
|
184
187
|
|
185
188
|
dest_hash = hash_email user['email']
|
@@ -232,10 +235,12 @@ module Lita
|
|
232
235
|
# instead: make one call for all users, then check
|
233
236
|
# to see if each is an active participant
|
234
237
|
def active_room_members(room_jid)
|
238
|
+
log.debug "looking up room jid: #{room_jid}"
|
235
239
|
data = room_data(room_jid)
|
240
|
+
log.debug "room_data: #{data.inspect}"
|
236
241
|
results = []
|
237
242
|
data['participants'].each do |p|
|
238
|
-
user = hipchat_api.users_show(p['
|
243
|
+
user = hipchat_api.users_show(p['user_id'])
|
239
244
|
next if user['user']['status'] != 'available'
|
240
245
|
next if exclude_user? user['user']
|
241
246
|
results << user['user']
|
@@ -250,13 +255,15 @@ module Lita
|
|
250
255
|
def room_data(room_jid)
|
251
256
|
room_id = room_id_from_jid room_jid
|
252
257
|
data = hipchat_api.rooms_show room_id
|
258
|
+
log.debug "room #{room_id} data: #{data.inspect}"
|
253
259
|
data['room']
|
254
260
|
end
|
255
261
|
|
256
262
|
def room_id_from_jid(room_jid)
|
257
263
|
data = hipchat_api.rooms_list
|
264
|
+
log.debug "all room data: #{data.inspect}"
|
258
265
|
room = data['rooms'].select {|r| r['xmpp_jid'] == room_jid}.first
|
259
|
-
room.nil? ? nil : room['
|
266
|
+
room.nil? ? nil : room['room_id']
|
260
267
|
end
|
261
268
|
|
262
269
|
end
|
data/lita-tipbot.gemspec
CHANGED
@@ -62,6 +62,37 @@ describe Lita::Handlers::Tipbot, lita_handler: true do
|
|
62
62
|
expect(replies.first).to eq('foo')
|
63
63
|
end
|
64
64
|
|
65
|
+
describe '#make_it_rain' do
|
66
|
+
let(:active_users) {
|
67
|
+
[
|
68
|
+
{
|
69
|
+
'name' => user.name,
|
70
|
+
'mention_name' => user.mention_name,
|
71
|
+
'email' => 'test@foo.com'
|
72
|
+
},
|
73
|
+
{
|
74
|
+
'name' => 'someguy',
|
75
|
+
'mention_name' => '@someguy',
|
76
|
+
'email' => 'someguy@foo.com'
|
77
|
+
}
|
78
|
+
]
|
79
|
+
}
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
allow(subject).to receive(:active_room_members).and_return(active_users)
|
83
|
+
subject.tipbot_api = double(tip: 'foo')
|
84
|
+
send_message("tipbot make it rain")
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'tips a user' do
|
88
|
+
expect(replies).to include("A coin for someguy!")
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'does not tip the tipper' do
|
92
|
+
expect(replies).to_not include("A coin for #{user.name}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
65
96
|
describe '#hash_email' do
|
66
97
|
it 'hashes properly' do
|
67
98
|
email = 'cchalfant@leafsoftwaresolutions.com'
|