lita-queue 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33fd47f0ec810e138b6c4ad01136929edb6c54ac
4
+ data.tar.gz: bbff179f4261205af069b78e88ddbc7fd946ab87
5
+ SHA512:
6
+ metadata.gz: a4dd70f59ae79592e5d0a03b2d1c8b8c514493f16952ea7ceb5ee38a2399d4550208ba492758ef3b2ca21d24973883da63747b8b52e67814a66d12a13f216180
7
+ data.tar.gz: 6a21b6e05bceb50fb4bf3f6fc675a6337dc7f10a5814e59f73aac45ea7574ead51b76268bd60d42d8150573b71d8b5ebb5b0a9c54402668afc8ab4389704fa5b
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tags
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ script: bundle exec rake
7
+ before_install:
8
+ - gem update --system
9
+ services:
10
+ - redis-server
@@ -0,0 +1,15 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ We follow [Keep a Changelog](http://keepachangelog.com/) format.
6
+
7
+ ## 0.1.0 - 2015-06-14
8
+ ### Added
9
+ - Initial plugin import with support for the following commands:
10
+ * lita queue
11
+ * lita queue me
12
+ * lita unqueue me
13
+ * lita queue next?
14
+ * lita queue next!
15
+ - RSpec, Travis CI and Coveralls support
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Gabriel Mazetto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # lita-queue
2
+
3
+ [![Build Status](https://travis-ci.org/brodock/lita-queue.svg?branch=master)](https://travis-ci.org/brodock/lita-queue)
4
+ [![Coverage Status](https://coveralls.io/repos/brodock/lita-queue/badge.svg?branch=master)](https://coveralls.io/r/brodock/lita-queue)
5
+
6
+ Lita handler to manage people queue per channel
7
+
8
+ ## Installation
9
+
10
+ Add lita-queue to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem "lita-queue"
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Manage a queue of users for any channel.
19
+
20
+ The following commands are available:
21
+ * lita queue
22
+ * lita queue me
23
+ * lita unqueue me
24
+ * lita queue next?
25
+ * lita queue next!
26
+
27
+ The following commands will be available in a further version:
28
+ * lita queue rotate!
29
+ * lita queue = [<new_queue,comma_separated>]
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/queue"
8
+
9
+ Lita::Handlers::Queue.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,110 @@
1
+ module Lita
2
+ module Handlers
3
+ class Queue < Handler
4
+
5
+ route(/^queue$/, :queue_list, command: :true)
6
+ route(/^queue me$/, :queue_me, command: :true)
7
+ route(/^unqueue me$/, :unqueue_me, command: :true)
8
+ route(/^queue next\?$/, :queue_list_next, command: :true)
9
+ route(/^queue next!$/, :queue_change_to_next, command: :true)
10
+ #route(/^queue rotate!$/, :queue_rotate, command: :true)
11
+ #route(/^queue = \[([^\]]*)\]\s*$$/, :queue_recreate, command: :true)
12
+
13
+ # API
14
+
15
+ def fetch_queue(room)
16
+ serialized = redis.get(room)
17
+
18
+ if serialized
19
+ JSON.parse(serialized)
20
+ else
21
+ []
22
+ end
23
+ end
24
+
25
+ def store_queue(room, queue)
26
+ redis.set room, queue.to_json
27
+ end
28
+
29
+ # Commands
30
+
31
+ def queue_list(response)
32
+ room = room_for(response)
33
+ queue = fetch_queue(room)
34
+
35
+ response.reply display_queue(queue, room)
36
+ end
37
+
38
+ def queue_me(response)
39
+ room = room_for(response)
40
+ queue = fetch_queue(room)
41
+ me = response.user.mention_name
42
+
43
+ if queue.include? me
44
+ response.reply "You are already on queue!"
45
+ else
46
+ queue << me
47
+ store_queue(room, queue)
48
+ response.reply "#{me} have been added to queue."
49
+ end
50
+ end
51
+
52
+ def unqueue_me(response)
53
+ room = room_for(response)
54
+ queue = fetch_queue(room)
55
+ me = response.user.mention_name
56
+
57
+ if queue.include? me
58
+ queue.delete(me)
59
+ store_queue(room, queue)
60
+ response.reply "#{me} have been removed from queue."
61
+ else
62
+ response.reply "You are not on queue!"
63
+ end
64
+ end
65
+
66
+ def queue_list_next(response)
67
+ room = room_for(response)
68
+ queue = fetch_queue(room)
69
+
70
+ if queue.empty?
71
+ response.reply "Queue is empty"
72
+ elsif queue.size == 1
73
+ response.reply "#{queue.first} is the last one on queue."
74
+ else
75
+ response.reply "#{queue[1]} will be the next!"
76
+ end
77
+ end
78
+
79
+ def queue_change_to_next(response)
80
+ room = room_for(response)
81
+ queue = fetch_queue(room)
82
+
83
+ unless queue.empty?
84
+ removed = queue.shift
85
+ store_queue(room, queue)
86
+ response.reply "#{removed} have been removed from queue"
87
+ response.reply "#{queue.first} is the next. Go ahead!" unless queue.empty?
88
+ end
89
+
90
+ response.reply display_queue(queue, room)
91
+ end
92
+
93
+ private
94
+
95
+ def room_for(response)
96
+ response.message.source.room || '--global--'
97
+ end
98
+
99
+ def display_queue(queue, room)
100
+ if queue.empty?
101
+ "Queue is empty"
102
+ else
103
+ "Queue for #{room}: #{queue}"
104
+ end
105
+ end
106
+ end
107
+
108
+ Lita.register_handler(Queue)
109
+ end
110
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-queue"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Gabriel Mazetto"]
5
+ spec.email = ["brodock@gmail.com"]
6
+ spec.description = "Lita plugin to manage channel specific queue"
7
+ spec.summary = "Lita plugin to manage channel specific queue"
8
+ spec.homepage = "https://github.com/brodock/lita-queue"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.3"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "pry-byebug"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "coveralls"
26
+ end
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ queue:
@@ -0,0 +1,130 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Queue, lita_handler: true do
4
+
5
+ user1 = Lita::User.create(100, name: 'User 1')
6
+ user2 = Lita::User.create(101, name: 'User 2')
7
+
8
+ # Routes
9
+ it { is_expected.to route_command("queue").to(:queue_list) }
10
+ it { is_expected.to route_command("queue me").to(:queue_me) }
11
+ it { is_expected.to route_command("unqueue me").to(:unqueue_me) }
12
+ it { is_expected.to route_command("queue next?").to(:queue_list_next) }
13
+ it { is_expected.to route_command("queue next!").to(:queue_change_to_next) }
14
+ #it { is_expected.to route_command("queue rotate!").to(:queue_rotate) }
15
+ #it { is_expected.to route_command("queue = [something,here]").to(:queue_recreate) }
16
+
17
+ let(:channel) { source.room || '--global--' }
18
+
19
+ # Commands
20
+ describe "#queue_list" do
21
+ context "when queue is empty" do
22
+ before { subject.store_queue(channel, []) }
23
+ it "replies with an empty queue message" do
24
+ send_command("queue")
25
+ expect(replies.last).to include("Queue is empty")
26
+ end
27
+ end
28
+
29
+ context "when queue has elements" do
30
+ before { subject.store_queue(channel, [user1.mention_name, user2.mention_name]) }
31
+
32
+ it "replies with a list of queue users" do
33
+ send_command("queue")
34
+ expect(replies.last).to include(user1.mention_name, user2.mention_name)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#queue_me" do
40
+ context "when I'm already queued" do
41
+ before { subject.store_queue(channel, [user.mention_name]) }
42
+ it "replies with an error message" do
43
+ send_command("queue me")
44
+ expect(replies.last).to include("already on queue")
45
+ end
46
+ end
47
+
48
+ context "when I'm not on queue" do
49
+ it "replies with a confirmation message" do
50
+ send_command("queue me")
51
+ expect(replies.last).to include("#{user.name} have been added to queue")
52
+ expect(subject.fetch_queue(channel)).to include(user.mention_name)
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#unqueue_me" do
58
+ context "when I'm already queued" do
59
+ before { subject.store_queue(channel, [user.mention_name]) }
60
+ it "replies with a confirmation and remove from queue" do
61
+ send_command("unqueue me")
62
+ expect(replies.last).to include("#{user.name} have been removed from queue")
63
+ expect(subject.fetch_queue(channel)).not_to include(user.mention_name)
64
+ end
65
+ end
66
+
67
+ context "when I'm not on queue" do
68
+ before { subject.store_queue(channel, []) }
69
+ it "replies with an error message" do
70
+ send_command("unqueue me")
71
+ expect(replies.last).to include("not on queue!")
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "#queue_list_next" do
77
+ context "when queue is empty" do
78
+ it "replies with an error message" do
79
+ send_command("queue next?")
80
+ expect(replies.last).to include("Queue is empty")
81
+ end
82
+ end
83
+
84
+ context "when queue has only one element" do
85
+ before { subject.store_queue(channel, [user1.mention_name]) }
86
+ it "replies listing current user on queue and warning that's the last one" do
87
+ send_command("queue next?")
88
+ expect(replies.last).to include(user1.mention_name)
89
+ expect(replies.last).to include("is the last one on queue")
90
+ end
91
+ end
92
+
93
+ context "when queue has more than one elements" do
94
+ before { subject.store_queue(channel, [user1.mention_name, user2.mention_name]) }
95
+ it "replies listing the next one on the queue" do
96
+ send_command("queue next?")
97
+ expect(replies.last).to include(user2.mention_name)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#queue_change_to_next" do
103
+ context "when queue is empty" do
104
+ it "replies with an error message" do
105
+ send_command("queue next!")
106
+ expect(replies.last).to include("Queue is empty")
107
+ end
108
+ end
109
+
110
+ context "when queue has elements" do
111
+ it "remove the first element and replies with current queue" do
112
+ subject.store_queue(channel, [user1.mention_name, user2.mention_name])
113
+
114
+ send_command("queue next!")
115
+ expect(replies.first).to include("#{user1.mention_name} have been removed from queue")
116
+ expect(replies[1]).to include("#{user2.mention_name} is the next")
117
+ expect(replies.last).to include(user2.mention_name)
118
+ expect(replies.last).not_to include(user1.mention_name)
119
+ end
120
+
121
+ it "replies with a notification message when removing the last element from queue" do
122
+ subject.store_queue(channel, [user2.mention_name])
123
+
124
+ send_command("queue next!")
125
+ expect(replies.first).to include("#{user2.mention_name} have been removed from queue")
126
+ expect(replies.last).to include("Queue is empty")
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-queue"
10
+ require "lita/rspec"
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Mazetto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Lita plugin to manage channel specific queue
126
+ email:
127
+ - brodock@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - CHANGELOG.md
135
+ - Gemfile
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - lib/lita-queue.rb
140
+ - lib/lita/handlers/queue.rb
141
+ - lita-queue.gemspec
142
+ - locales/en.yml
143
+ - spec/lita/handlers/queue_spec.rb
144
+ - spec/spec_helper.rb
145
+ - templates/.gitkeep
146
+ homepage: https://github.com/brodock/lita-queue
147
+ licenses:
148
+ - MIT
149
+ metadata:
150
+ lita_plugin_type: handler
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.4.6
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Lita plugin to manage channel specific queue
171
+ test_files:
172
+ - spec/lita/handlers/queue_spec.rb
173
+ - spec/spec_helper.rb