lita-debug-queue 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/NEWS.md +6 -0
- data/lib/lita/handlers/debug_queue.rb +38 -33
- data/lib/lita/handlers/room_finder.rb +23 -0
- data/lib/lita/handlers/room_queue.rb +41 -0
- data/lib/lita-debug-queue.rb +2 -0
- data/lita-debug-queue.gemspec +1 -1
- data/spec/lita/handlers/help_queue_spec.rb +22 -20
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a2e7ac111f8ab2cc860f5a352ef7c3465c63cdd
|
4
|
+
data.tar.gz: 32d4111430293f16a405becfdfd73088d8299ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 344e268f20bfe2ea95479bc41d3dff57a53cf3cb631da42599db1c8be175e554aafc6cd876dd2d5e72a9a579b53fa04dc3e8fb55a46137990ddd421b9ce85f57
|
7
|
+
data.tar.gz: 50a448fca9c44c970f2b340806007e1919a21331f6a66c1cb1b2052173fc58115198b4668b88990217b908f72098965c1091a2432ab36752d2dc298594a104af
|
data/NEWS.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## News
|
2
2
|
|
3
|
+
### 0.1.2 (2015-08-31)
|
4
|
+
|
5
|
+
* Add docstrings for built-in Lita help.
|
6
|
+
* Fix inconsistency in the way the room is determined.
|
7
|
+
* Fix student not being notified on instructor "debug next".
|
8
|
+
|
3
9
|
### 0.1.1 (2015-08-28)
|
4
10
|
|
5
11
|
* Quick workaround for issue #44 in lita-slack.
|
@@ -3,33 +3,37 @@ module Lita
|
|
3
3
|
class DebugQueue < Handler
|
4
4
|
config :classrooms # A mapping from instructor names to classroom channels.
|
5
5
|
|
6
|
-
route(/^debug me$/, :add, command: true,
|
7
|
-
|
8
|
-
route(/^debug
|
9
|
-
|
6
|
+
route(/^debug me$/, :add, command: true,
|
7
|
+
help: { 'debug me' => 'Put your name in the queue for debugging help.' })
|
8
|
+
route(/^debug nvm$/, :cancel, command: true,
|
9
|
+
help: { 'debug nvm' => 'Remove your name from the queue for debugging help.' })
|
10
|
+
route(/^debug queue$/, :show, command: true,
|
11
|
+
help: { 'debug queue' => 'Show the current queue for your class.' })
|
12
|
+
route(/^debug count$/, :count, command: true,
|
13
|
+
help: { 'debug count' => 'Count the number of people waiting for help.' })
|
10
14
|
route(/^debug next$/, :next, command: true, restrict_to: [:instructors],
|
11
|
-
help: { })
|
15
|
+
help: { 'debug next' => 'Notify the next student to be helped.' })
|
12
16
|
route(/^debug drop\s+(.+)$/, :drop, command: true, restrict_to: [:instructors],
|
13
|
-
help: { })
|
17
|
+
help: { 'debug drop NAME' => 'Remove the student with NAME from the queue.' })
|
14
18
|
route(/^debug clear$/, :clear, command: true, restrict_to: [:instructors],
|
15
|
-
help: { })
|
19
|
+
help: { 'debug clear' => 'Empty the queue.' })
|
16
20
|
|
17
21
|
def add(response)
|
18
22
|
return unless check_room!(response)
|
19
23
|
student = response.user.mention_name
|
20
|
-
if
|
24
|
+
if @room.include?(student)
|
21
25
|
response.reply("#{student}: Easy there killer. You're already on the list.")
|
22
26
|
else
|
23
|
-
|
24
|
-
response.reply("#{student}: Help is
|
27
|
+
@room.add(student)
|
28
|
+
response.reply("#{student}: Help is coming soon.")
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
32
|
def cancel(response)
|
29
33
|
return unless check_room!(response)
|
30
34
|
student = response.user.mention_name
|
31
|
-
if
|
32
|
-
|
35
|
+
if @room.include?(student)
|
36
|
+
@room.remove(student)
|
33
37
|
response.reply("#{student}: Glad you figured it out! :)")
|
34
38
|
else
|
35
39
|
response.reply("#{student}: You know you're not in the queue, right?")
|
@@ -38,48 +42,49 @@ module Lita
|
|
38
42
|
|
39
43
|
def show(response)
|
40
44
|
return unless check_room!(response)
|
41
|
-
response.reply("Queue for #{@room} => #{
|
45
|
+
response.reply("Queue for #{@room} => #{@room.queue}")
|
42
46
|
end
|
43
47
|
|
44
48
|
def count(response)
|
45
49
|
return unless check_room!(response)
|
46
|
-
response.reply("Hackers seeking fresh eyes: #{
|
50
|
+
response.reply("Hackers seeking fresh eyes: #{@room.count}")
|
47
51
|
end
|
48
52
|
|
49
53
|
def next(response)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
return unless check_room!(response)
|
55
|
+
if @room.count.zero?
|
56
|
+
response.reply("The queue is empty. Sounds like you could use a break. :)")
|
57
|
+
else
|
58
|
+
student = @room.next
|
59
|
+
robot.send_message(student, "@#{student}: You're up. Let's debug :allthethings:!")
|
60
|
+
response.reply("#{student} is up next and has been notified.")
|
61
|
+
end
|
55
62
|
end
|
56
63
|
|
57
64
|
def drop(response)
|
58
|
-
|
59
|
-
student = response.
|
60
|
-
|
61
|
-
|
65
|
+
return unless check_room!(response)
|
66
|
+
student = response.args[1]
|
67
|
+
if @room.include?(student)
|
68
|
+
@room.remove(student)
|
69
|
+
response.reply("#{student} has been removed from the queue.")
|
70
|
+
else
|
71
|
+
response.reply("#{student} is not in the queue for #{@room}!")
|
72
|
+
end
|
62
73
|
end
|
63
74
|
|
64
75
|
def clear(response)
|
65
|
-
|
66
|
-
|
76
|
+
return unless check_room!(response)
|
77
|
+
@room.clear!
|
67
78
|
response.reply("Sounds like time for :beer: and ping pong!")
|
68
79
|
end
|
69
80
|
|
70
81
|
private
|
82
|
+
|
71
83
|
def check_room!(response)
|
72
|
-
|
73
|
-
# See lita-slack Issue #44
|
74
|
-
@room = Lita::Room.find_by_id(response.message.source.room).name
|
84
|
+
@room = RoomFinder.for(config.classrooms, response, redis)
|
75
85
|
response.reply_privately("You must be in the class channel to send this message.") unless @room
|
76
86
|
@room
|
77
87
|
end
|
78
|
-
|
79
|
-
def room_queue
|
80
|
-
room = redis.get(@room)
|
81
|
-
room ? MultiJson.load(room) : []
|
82
|
-
end
|
83
88
|
end
|
84
89
|
|
85
90
|
Lita.register_handler(DebugQueue)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class RoomFinder
|
4
|
+
def self.for(rooms, response, redis)
|
5
|
+
sender = response.user.mention_name
|
6
|
+
room = response.message.source.room_object
|
7
|
+
if rooms.has_key?(sender)
|
8
|
+
name = rooms[sender]
|
9
|
+
RoomQueue.new(name, redis)
|
10
|
+
elsif room
|
11
|
+
name = self.get_room_name(room)
|
12
|
+
RoomQueue.new(name, redis)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# KLUDGE: The following is a hack as the current room_object is incorrect. (lita-slack issue #44)
|
17
|
+
def self.get_room_name(room)
|
18
|
+
# KLUDGE: And this conditional is a hack since the test rooms are mocked.
|
19
|
+
room.id == room.name ? room.name : Lita::Room.find_by_id(room.id).name(room)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class RoomQueue
|
4
|
+
def initialize(name, redis)
|
5
|
+
@name = name
|
6
|
+
@redis = redis
|
7
|
+
end
|
8
|
+
|
9
|
+
def queue
|
10
|
+
data = @redis.get(@name)
|
11
|
+
data ? MultiJson.load(data) : []
|
12
|
+
end
|
13
|
+
|
14
|
+
def count
|
15
|
+
self.queue.length
|
16
|
+
end
|
17
|
+
|
18
|
+
def include?(student)
|
19
|
+
self.queue.include?(student)
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(student)
|
23
|
+
@redis.set(@name, self.queue.push(student))
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove(student)
|
27
|
+
@redis.set(@name, self.queue.reject { |x| x == student })
|
28
|
+
end
|
29
|
+
|
30
|
+
def next
|
31
|
+
student = self.queue.pop
|
32
|
+
@redis.set(@name, self.queue.reject { |x| x == student })
|
33
|
+
student
|
34
|
+
end
|
35
|
+
|
36
|
+
def clear!
|
37
|
+
@redis.del(@name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/lita-debug-queue.rb
CHANGED
@@ -4,6 +4,8 @@ Lita.load_locales Dir[File.expand_path(
|
|
4
4
|
File.join("..", "..", "locales", "*.yml"), __FILE__
|
5
5
|
)]
|
6
6
|
|
7
|
+
require "lita/handlers/room_finder"
|
8
|
+
require "lita/handlers/room_queue"
|
7
9
|
require "lita/handlers/debug_queue"
|
8
10
|
|
9
11
|
Lita::Handlers::DebugQueue.template_root File.expand_path(
|
data/lita-debug-queue.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-debug-queue"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.2"
|
4
4
|
spec.authors = ["Brit Butler"]
|
5
5
|
spec.email = ["brit@kingcons.io"]
|
6
6
|
spec.description = "Queue tracking of users who need debugging help with per-channel management"
|
@@ -5,6 +5,13 @@ describe Lita::Handlers::DebugQueue, lita_handler: true do
|
|
5
5
|
let(:brit) { Lita::User.create(789, mention_name: "brit") }
|
6
6
|
let(:dylan) { Lita::User.create(123, mention_name: "dylan") }
|
7
7
|
let(:rails) { Lita::Room.new("rails") }
|
8
|
+
before(:each) do
|
9
|
+
registry.config.handlers.debug_queue.classrooms = {
|
10
|
+
'brit' => 'rails'
|
11
|
+
}
|
12
|
+
@auth = Lita::Authorization.new(registry.config)
|
13
|
+
@auth.add_user_to_group!(brit, :instructors)
|
14
|
+
end
|
8
15
|
|
9
16
|
## Routes
|
10
17
|
it { is_expected.to route_command("debug me").to(:add) }
|
@@ -15,40 +22,39 @@ describe Lita::Handlers::DebugQueue, lita_handler: true do
|
|
15
22
|
it { is_expected.to route_command("debug drop phteven").with_authorization_for(:instructors).to(:drop) }
|
16
23
|
it { is_expected.to route_command("debug clear").with_authorization_for(:instructors).to(:clear) }
|
17
24
|
|
18
|
-
|
19
|
-
context "user commands" do
|
25
|
+
context "a general user" do
|
20
26
|
let(:ocaml) { Lita::Room.new("ocaml") }
|
21
27
|
|
22
|
-
it "
|
28
|
+
it "can't send messages outside the class channel" do
|
23
29
|
["debug me", "debug nvm", "debug queue", "debug count"].each do |cmd|
|
24
30
|
send_command(cmd, as: dylan)
|
25
31
|
expect(replies.last).to start_with("You must be in the class channel")
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
|
-
it "
|
35
|
+
it "can queue themselves for help" do
|
30
36
|
send_command("debug me", as: dylan, from: rails)
|
31
|
-
expect(replies.last).to start_with("dylan: Help is
|
37
|
+
expect(replies.last).to start_with("dylan: Help is ")
|
32
38
|
end
|
33
39
|
|
34
|
-
it "
|
40
|
+
it "can't queue themselves twice" do
|
35
41
|
send_command("debug me", as: dylan, from: rails)
|
36
42
|
send_command("debug me", as: dylan, from: rails)
|
37
43
|
expect(replies.last).to start_with("dylan: Easy there killer. You're already on the list.")
|
38
44
|
end
|
39
45
|
|
40
|
-
it "
|
46
|
+
it "can remove themselves if they figure it out" do
|
41
47
|
send_command("debug me", as: dylan, from: rails)
|
42
48
|
send_command("debug nvm", as: dylan, from: rails)
|
43
49
|
expect(replies.last).to start_with("dylan: Glad you figured it out! :)")
|
44
50
|
end
|
45
51
|
|
46
|
-
it "
|
52
|
+
it "can't remove themselves if they aren't in the queue" do
|
47
53
|
send_command("debug nvm", as: dylan, from: rails)
|
48
54
|
expect(replies.last).to start_with("dylan: You know you're not in the queue, right?")
|
49
55
|
end
|
50
56
|
|
51
|
-
it "
|
57
|
+
it "can get an up to date count of people in that room's queue" do
|
52
58
|
send_command("debug me", as: vedika, from: rails)
|
53
59
|
send_command("debug count", from: rails)
|
54
60
|
expect(replies.last).to start_with("Hackers seeking fresh eyes: 1")
|
@@ -66,17 +72,13 @@ describe Lita::Handlers::DebugQueue, lita_handler: true do
|
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
|
-
context "instructor
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
74
|
-
@auth = Lita::Authorization.new(registry.config)
|
75
|
-
@auth.add_user_to_group!(brit, :instructors)
|
75
|
+
context "an instructor" do
|
76
|
+
it "doesn't need to say messages in channel since their classroom is known" do
|
77
|
+
send_command("debug count", as: brit)
|
78
|
+
expect(replies.last).to start_with("Hackers seeking fresh eyes: 0")
|
76
79
|
end
|
77
80
|
|
78
|
-
|
79
|
-
it "allows instructors to notify the next student and pop them from the queue" do
|
81
|
+
it "can notify the next student and pop them from the queue" do
|
80
82
|
send_command("debug me", as: vedika, from: rails)
|
81
83
|
send_command("debug next", as: brit)
|
82
84
|
expect(replies.last).to start_with("vedika is up next and has been notified.")
|
@@ -84,7 +86,7 @@ describe Lita::Handlers::DebugQueue, lita_handler: true do
|
|
84
86
|
expect(replies.last).to start_with("Hackers seeking fresh eyes: 0")
|
85
87
|
end
|
86
88
|
|
87
|
-
it "
|
89
|
+
it "can remove a student from the queue by name" do
|
88
90
|
send_command("debug me", as: dylan, from: rails)
|
89
91
|
send_command("debug drop dylan", as: brit)
|
90
92
|
expect(replies.last).to start_with("dylan has been removed from the queue.")
|
@@ -92,7 +94,7 @@ describe Lita::Handlers::DebugQueue, lita_handler: true do
|
|
92
94
|
expect(replies.last).to start_with("Hackers seeking fresh eyes: 0")
|
93
95
|
end
|
94
96
|
|
95
|
-
it "
|
97
|
+
it "can clear the queue completely" do
|
96
98
|
send_command("debug me", as: vedika, from: rails)
|
97
99
|
send_command("debug me", as: dylan, from: rails)
|
98
100
|
send_command("debug clear", as: brit)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-debug-queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brit Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- lib/lita-debug-queue.rb
|
111
111
|
- lib/lita/handlers/debug_queue.rb
|
112
|
+
- lib/lita/handlers/room_finder.rb
|
113
|
+
- lib/lita/handlers/room_queue.rb
|
112
114
|
- lita-debug-queue.gemspec
|
113
115
|
- locales/en.yml
|
114
116
|
- spec/lita/handlers/help_queue_spec.rb
|