lita-team 1.0.0 → 2.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +243 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +1 -1
  5. data/README.md +2 -1
  6. data/lib/lita/handlers/add_member_to_team.rb +74 -0
  7. data/lib/lita/handlers/block_team.rb +42 -0
  8. data/lib/lita/handlers/clear_team.rb +38 -0
  9. data/lib/lita/handlers/confirm_member.rb +56 -0
  10. data/lib/lita/handlers/create_team.rb +38 -0
  11. data/lib/lita/handlers/delete_team.rb +26 -0
  12. data/lib/lita/handlers/list_team.rb +36 -0
  13. data/lib/lita/handlers/list_teams.rb +35 -0
  14. data/lib/lita/handlers/remove_member_from_team.rb +63 -0
  15. data/lib/lita/handlers/team.rb +2 -53
  16. data/lib/lita/handlers/update_team.rb +63 -0
  17. data/lib/lita-team.rb +12 -16
  18. data/lita-team.gemspec +2 -2
  19. data/locales/en.yml +21 -15
  20. data/spec/lita/handlers/add_member_to_team_spec.rb +92 -0
  21. data/spec/lita/handlers/block_team_spec.rb +29 -0
  22. data/spec/lita/handlers/clear_team_spec.rb +21 -0
  23. data/spec/lita/handlers/confirm_member_spec.rb +82 -0
  24. data/spec/lita/handlers/create_team_spec.rb +18 -0
  25. data/spec/lita/handlers/delete_team_spec.rb +20 -0
  26. data/spec/lita/handlers/list_team_spec.rb +65 -0
  27. data/spec/lita/handlers/list_teams_spec.rb +26 -0
  28. data/spec/lita/handlers/remove_member_from_team_spec.rb +104 -0
  29. data/spec/lita/handlers/team_spec.rb +0 -199
  30. data/spec/lita/handlers/update_team_spec.rb +41 -0
  31. data/spec/spec_helper.rb +1 -1
  32. data/templates/list_team.erb +8 -5
  33. data/templates/list_teams.erb +2 -8
  34. data/templates/member_added_to_team.erb +2 -2
  35. data/templates/member_confirmed.erb +4 -0
  36. data/templates/member_not_on_team.erb +0 -0
  37. data/templates/member_removed_from_team.erb +3 -3
  38. data/templates/team_already_exists.erb +1 -0
  39. data/templates/team_blocked.erb +1 -0
  40. data/templates/team_cannot_perform_operation.erb +1 -0
  41. data/templates/team_created.erb +1 -0
  42. data/templates/team_deleted.erb +1 -0
  43. data/templates/team_not_found.erb +1 -0
  44. data/templates/team_unblocked.erb +1 -0
  45. data/templates/team_updated.erb +1 -0
  46. metadata +46 -17
  47. data/lib/lita/actions/add_member_to_team.rb +0 -38
  48. data/lib/lita/actions/base.rb +0 -28
  49. data/lib/lita/actions/clear_team.rb +0 -30
  50. data/lib/lita/actions/create_team.rb +0 -21
  51. data/lib/lita/actions/delete_team.rb +0 -21
  52. data/lib/lita/actions/list_team.rb +0 -25
  53. data/lib/lita/actions/list_teams.rb +0 -11
  54. data/lib/lita/actions/remove_member_from_team.rb +0 -37
  55. data/lib/lita/member.rb +0 -17
  56. data/lib/lita/store/member.rb +0 -32
  57. data/lib/lita/store/team.rb +0 -34
  58. data/lib/lita/team.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3063c4d97c93c2aec90fbca5c5cd0187be403e8b
4
- data.tar.gz: c81a31b980fbac18ce25920033b69518657348d9
3
+ metadata.gz: 8ed605cdde13081275049d971e030093180a6289
4
+ data.tar.gz: f5f84bfbb4351c44541160802739958d607daf70
5
5
  SHA512:
6
- metadata.gz: 3018309d640b32259fde30ccaf450515615fbd620398908b1ae0e5f3c887a4ad311f27f433f8e06b5e389efedcb0803f774cccf650eeaf9daeac0547118020c1
7
- data.tar.gz: cde6b8fbcf5a6255981927ee0e50082398ada98d0ba33df1af6a58e331e40e8794160582445a549e0263c7071050f6a4a974bcaa22f9fb4e1f4f39576e77ce79
6
+ metadata.gz: d49dec67ce61f67e7e9dfd3cbeeda8126d17c16fb2b8c949b76062ca86b216f8a3740d02cc109214a6eefb5e9556ab68aade7bfd1a0c38a91629429707237d4d
7
+ data.tar.gz: e81b0780441ecb6c1cdb11da8fc5f03787badedc74b310d6f7eae6126c154fdfd4ddffc7de80eefbc410bf5406c1d64f2d54670aed1d4f4253cadc2e199e8954
data/.rubocop.yml ADDED
@@ -0,0 +1,243 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ - "db/schema.rb"
5
+ UseCache: false
6
+ Style/CollectionMethods:
7
+ Description: Preferred collection methods.
8
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
9
+ Enabled: true
10
+ PreferredMethods:
11
+ collect: map
12
+ collect!: map!
13
+ find: detect
14
+ find_all: select
15
+ reduce: inject
16
+ Style/DotPosition:
17
+ Description: Checks the position of the dot in multi-line method calls.
18
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
19
+ Enabled: true
20
+ EnforcedStyle: trailing
21
+ SupportedStyles:
22
+ - leading
23
+ - trailing
24
+ Style/FileName:
25
+ Description: Use snake_case for source file names.
26
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
27
+ Enabled: false
28
+ Exclude: []
29
+ Style/GuardClause:
30
+ Description: Check for conditionals that can be replaced with guard clauses
31
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
32
+ Enabled: false
33
+ MinBodyLength: 1
34
+ Style/IfUnlessModifier:
35
+ Description: Favor modifier if/unless usage when you have a single-line body.
36
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
37
+ Enabled: false
38
+ MaxLineLength: 80
39
+ Style/OptionHash:
40
+ Description: Don't use option hashes when you can use keyword arguments.
41
+ Enabled: false
42
+ Style/PercentLiteralDelimiters:
43
+ Description: Use `%`-literal delimiters consistently
44
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
45
+ Enabled: false
46
+ PreferredDelimiters:
47
+ "%": "()"
48
+ "%i": "()"
49
+ "%q": "()"
50
+ "%Q": "()"
51
+ "%r": "{}"
52
+ "%s": "()"
53
+ "%w": "()"
54
+ "%W": "()"
55
+ "%x": "()"
56
+ Style/PredicateName:
57
+ Description: Check the names of predicate methods.
58
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
59
+ Enabled: true
60
+ NamePrefix:
61
+ - is_
62
+ - has_
63
+ - have_
64
+ NamePrefixBlacklist:
65
+ - is_
66
+ Exclude:
67
+ - spec/**/*
68
+ Style/RaiseArgs:
69
+ Description: Checks the arguments passed to raise/fail.
70
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
71
+ Enabled: false
72
+ EnforcedStyle: exploded
73
+ SupportedStyles:
74
+ - compact
75
+ - exploded
76
+ Style/SignalException:
77
+ Description: Checks for proper usage of fail and raise.
78
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
79
+ Enabled: false
80
+ EnforcedStyle: semantic
81
+ SupportedStyles:
82
+ - only_raise
83
+ - only_fail
84
+ - semantic
85
+ Style/SingleLineBlockParams:
86
+ Description: Enforces the names of some block params.
87
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
88
+ Enabled: false
89
+ Methods:
90
+ - reduce:
91
+ - a
92
+ - e
93
+ - inject:
94
+ - a
95
+ - e
96
+ Style/SingleLineMethods:
97
+ Description: Avoid single-line methods.
98
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
99
+ Enabled: false
100
+ AllowIfMethodIsEmpty: true
101
+ Style/StringLiterals:
102
+ Description: Checks if uses of quotes match the configured preference.
103
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
104
+ Enabled: true
105
+ EnforcedStyle: double_quotes
106
+ SupportedStyles:
107
+ - single_quotes
108
+ - double_quotes
109
+ Style/StringLiteralsInInterpolation:
110
+ Description: Checks if uses of quotes inside expressions in interpolated strings
111
+ match the configured preference.
112
+ Enabled: true
113
+ EnforcedStyle: single_quotes
114
+ SupportedStyles:
115
+ - single_quotes
116
+ - double_quotes
117
+ Style/TrailingCommaInArguments:
118
+ Description: 'Checks for trailing comma in argument lists.'
119
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
120
+ Enabled: false
121
+ EnforcedStyleForMultiline: no_comma
122
+ SupportedStyles:
123
+ - comma
124
+ - consistent_comma
125
+ - no_comma
126
+ Style/TrailingCommaInLiteral:
127
+ Description: 'Checks for trailing comma in array and hash literals.'
128
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
129
+ Enabled: false
130
+ EnforcedStyleForMultiline: no_comma
131
+ SupportedStyles:
132
+ - comma
133
+ - consistent_comma
134
+ - no_comma
135
+ Metrics/AbcSize:
136
+ Description: A calculated magnitude based on number of assignments, branches, and
137
+ conditions.
138
+ Enabled: false
139
+ Max: 15
140
+ Metrics/ClassLength:
141
+ Description: Avoid classes longer than 100 lines of code.
142
+ Enabled: false
143
+ CountComments: false
144
+ Max: 100
145
+ Metrics/ModuleLength:
146
+ CountComments: false
147
+ Max: 100
148
+ Description: Avoid modules longer than 100 lines of code.
149
+ Enabled: false
150
+ Metrics/CyclomaticComplexity:
151
+ Description: A complexity metric that is strongly correlated to the number of test
152
+ cases needed to validate a method.
153
+ Enabled: false
154
+ Max: 6
155
+ Metrics/MethodLength:
156
+ Description: Avoid methods longer than 10 lines of code.
157
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
158
+ Enabled: false
159
+ CountComments: false
160
+ Max: 10
161
+ Metrics/ParameterLists:
162
+ Description: Avoid parameter lists longer than three or four parameters.
163
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
164
+ Enabled: false
165
+ Max: 5
166
+ CountKeywordArgs: true
167
+ Metrics/PerceivedComplexity:
168
+ Description: A complexity metric geared towards measuring complexity for a human
169
+ reader.
170
+ Enabled: false
171
+ Max: 7
172
+ Lint/AssignmentInCondition:
173
+ Description: Don't use assignment in conditions.
174
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
175
+ Enabled: false
176
+ AllowSafeAssignment: true
177
+ Style/InlineComment:
178
+ Description: Avoid inline comments.
179
+ Enabled: false
180
+ Style/AccessorMethodName:
181
+ Description: Check the naming of accessor methods for get_/set_.
182
+ Enabled: false
183
+ Style/Alias:
184
+ Description: Use alias_method instead of alias.
185
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
186
+ Enabled: false
187
+ Style/Documentation:
188
+ Description: Document classes and non-namespace modules.
189
+ Enabled: false
190
+ Style/DoubleNegation:
191
+ Description: Checks for uses of double negation (!!).
192
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
193
+ Enabled: false
194
+ Style/EachWithObject:
195
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
196
+ Enabled: false
197
+ Style/EmptyLiteral:
198
+ Description: Prefer literals to Array.new/Hash.new/String.new.
199
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
200
+ Enabled: false
201
+ Style/ModuleFunction:
202
+ Description: Checks for usage of `extend self` in modules.
203
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
204
+ Enabled: false
205
+ Style/OneLineConditional:
206
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
207
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
208
+ Enabled: false
209
+ Style/PerlBackrefs:
210
+ Description: Avoid Perl-style regex back references.
211
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
212
+ Enabled: false
213
+ Style/Send:
214
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
215
+ may overlap with existing methods.
216
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
217
+ Enabled: false
218
+ Style/SpecialGlobalVars:
219
+ Description: Avoid Perl-style global variables.
220
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
221
+ Enabled: false
222
+ Style/VariableInterpolation:
223
+ Description: Don't interpolate global, instance and class variables directly in
224
+ strings.
225
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
226
+ Enabled: false
227
+ Style/WhenThen:
228
+ Description: Use when x then ... for one-line cases.
229
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
230
+ Enabled: false
231
+ Lint/EachWithObjectArgument:
232
+ Description: Check for immutable argument given to each_with_object.
233
+ Enabled: true
234
+ Lint/HandleExceptions:
235
+ Description: Don't suppress exception.
236
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
237
+ Enabled: false
238
+ Lint/LiteralInCondition:
239
+ Description: Checks of literals used in conditions.
240
+ Enabled: false
241
+ Lint/LiteralInInterpolation:
242
+ Description: Checks for literals used in interpolation.
243
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 2.3.0
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.2.2
4
+ - 2.3.0
5
5
  script: bundle exec rake
6
6
  before_install:
7
7
  - gem update --system
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/EdgarOrtegaRamirez/lita-team.svg?branch=master)](https://travis-ci.org/EdgarOrtegaRamirez/lita-team)
4
4
  [![Coverage Status](https://coveralls.io/repos/EdgarOrtegaRamirez/lita-team/badge.svg?branch=master)](https://coveralls.io/r/EdgarOrtegaRamirez/lita-team?branch=master)
5
5
  [![Code Climate](https://codeclimate.com/github/EdgarOrtegaRamirez/lita-team/badges/gpa.svg)](https://codeclimate.com/github/EdgarOrtegaRamirez/lita-team)
6
+ [![Security](https://hakiri.io/github/EdgarOrtegaRamirez/lita-team/master.svg)](https://hakiri.io/github/EdgarOrtegaRamirez/lita-team/master)
6
7
 
7
8
  Create and manage the members of a team with Lita
8
9
 
@@ -11,7 +12,7 @@ Create and manage the members of a team with Lita
11
12
  Add lita-team to your Lita instance's Gemfile:
12
13
 
13
14
  ``` ruby
14
- gem "lita-team"
15
+ gem 'lita-team'
15
16
  ```
16
17
 
17
18
  ## Usage
@@ -0,0 +1,74 @@
1
+ module Lita
2
+ module Handlers
3
+ class AddMemberToTeam < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(
8
+ /(\S*) team (\+1|add me|add (\S*))$/i,
9
+ :add,
10
+ command: true,
11
+ help: {
12
+ "<name> team +1" => "add me to team",
13
+ "<name> team add me" => "add me to team",
14
+ "<name> team add <member>" => "add member to team"
15
+ }
16
+ )
17
+
18
+ def add(response)
19
+ team_name = response.match_data[1]
20
+ if team = get_team(team_name)
21
+ if team[:limit] && team[:limit] <= team[:members].count
22
+ return response.reply(
23
+ render_template(:team_cannot_perform_operation,
24
+ team_name: team_name)
25
+ )
26
+ end
27
+ member_name = (response.match_data[3] ||
28
+ response.user.mention_name).delete("@")
29
+ if team[:members].key?(member_name.to_sym)
30
+ return response.reply(
31
+ t("member.already_in_team",
32
+ team_name: team_name,
33
+ member_name: member_name)
34
+ )
35
+ end
36
+ member = member_data(member_name)
37
+ count_was = team[:members].count
38
+ team[:members][member_name] = member
39
+ redis.set(team_name, MultiJson.dump(team))
40
+ response.reply(
41
+ render_template(:member_added_to_team,
42
+ team_name: team_name,
43
+ member_name: member[:name],
44
+ count: count_was)
45
+ )
46
+ else
47
+ response.reply(render_template(:team_not_found, team_name: team_name))
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def get_team(team_name)
54
+ data = redis.get(team_name)
55
+ MultiJson.load(data, symbolize_keys: true) if data
56
+ end
57
+
58
+ def member_data(member_name)
59
+ if lita_user = Lita::User.fuzzy_find(member_name)
60
+ {
61
+ id: lita_user.id,
62
+ name: lita_user.name,
63
+ mention_name: lita_user.mention_name,
64
+ confirmed: false
65
+ }
66
+ else
67
+ { name: member_name, confirmed: false }
68
+ end
69
+ end
70
+
71
+ Lita.register_handler(self)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,42 @@
1
+ module Lita
2
+ module Handlers
3
+ class BlockTeam < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(
8
+ /(block|unblock) (\S*) team/i,
9
+ :toggle_block,
10
+ command: true,
11
+ help: {
12
+ "block <name> team" => "block team called <name>",
13
+ "unblock <name> team" => "unblock team called <name>"
14
+ }
15
+ )
16
+
17
+ def toggle_block(response)
18
+ team_name = response.match_data[2]
19
+ action = response.match_data[1]
20
+ if team = get_team(team_name)
21
+ team[:limit] = action == "block" ? team[:members].size : nil
22
+ redis.set(team[:name], MultiJson.dump(team))
23
+ response.reply(
24
+ render_template("team_#{action}ed".to_sym, team_name: team_name)
25
+ )
26
+ else
27
+ response.reply(
28
+ render_template(:team_not_found, team_name: team_name)
29
+ )
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def get_team(team_name)
36
+ data = redis.get(team_name)
37
+ MultiJson.load(data, symbolize_keys: true) if data
38
+ end
39
+ Lita.register_handler(self)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ module Lita
2
+ module Handlers
3
+ class ClearTeam < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(
8
+ /(\S*) team (clear|empty)/i,
9
+ :clear,
10
+ command: true,
11
+ help: {
12
+ "<name> team clear" => "clear team list",
13
+ "<name> team empty" => "clear team list"
14
+ }
15
+ )
16
+
17
+ def clear(response)
18
+ team_name = response.match_data[1]
19
+ if team = get_team(team_name)
20
+ team[:members] = {}
21
+ redis.set(team[:name], MultiJson.dump(team))
22
+ response.reply(t(:cleared, team_name: team_name))
23
+ else
24
+ response.reply(render_template(:team_not_found, team_name: team_name))
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def get_team(team_name)
31
+ data = redis.get(team_name)
32
+ MultiJson.load(data, symbolize_keys: true) if data
33
+ end
34
+
35
+ Lita.register_handler(self)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,56 @@
1
+ module Lita
2
+ module Handlers
3
+ class ConfirmMember < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(
8
+ /(\S*) team confirm (me|(\S*))$/i,
9
+ :confirm,
10
+ command: true,
11
+ help: {
12
+ "<name> team confirm me" => "confirm attendance",
13
+ "<name> team remove <member>" => "confirm member attendance"
14
+ }
15
+ )
16
+
17
+ def confirm(response)
18
+ team_name = response.match_data[1]
19
+ if team = get_team(team_name)
20
+ member_name = (response.match_data[3] ||
21
+ response.user.mention_name).delete("@")
22
+ if member = team[:members][member_name.to_sym]
23
+ member[:confirmed] = true
24
+ unconfirmed = team[:members].count { |_k, v| !v[:confirmed] }
25
+ redis.set(team_name, MultiJson.dump(team))
26
+ response.reply(
27
+ render_template(:member_confirmed,
28
+ team_name: team_name,
29
+ member_name: member[:name],
30
+ count: unconfirmed)
31
+ )
32
+ else
33
+ response.reply(
34
+ t("member.not_in_team",
35
+ team_name: team_name,
36
+ member_name: member_name)
37
+ )
38
+ end
39
+ else
40
+ response.reply(
41
+ render_template(:team_not_found, team_name: team_name)
42
+ )
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def get_team(team_name)
49
+ data = redis.get(team_name)
50
+ MultiJson.load(data, symbolize_keys: true) if data
51
+ end
52
+
53
+ Lita.register_handler(self)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,38 @@
1
+ module Lita
2
+ module Handlers
3
+ class CreateTeam < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(
8
+ /create (\S*) team/i,
9
+ :create,
10
+ command: true,
11
+ help: {
12
+ "create <name> team" => "create team called <name>"
13
+ }
14
+ )
15
+
16
+ def create(response)
17
+ team_name = response.match_data[1]
18
+ if redis.exists(team_name)
19
+ response.reply(
20
+ render_template(:team_already_exists, team_name: team_name)
21
+ )
22
+ else
23
+ data = {
24
+ name: team_name,
25
+ limit: nil,
26
+ location: nil,
27
+ icon: nil,
28
+ members: {}
29
+ }
30
+ redis.set(team_name, MultiJson.dump(data))
31
+ response.reply(render_template(:team_created, team_name: team_name))
32
+ end
33
+ end
34
+
35
+ Lita.register_handler(self)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ module Lita
2
+ module Handlers
3
+ class DeleteTeam < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(/(delete|remove) (\S*) team/i, :delete, command: true, help:
8
+ {
9
+ "delete <name> team" => "delete team called <name>",
10
+ "remove <name> team" => "delete team called <name>"
11
+ })
12
+
13
+ def delete(response)
14
+ team_name = response.match_data[2]
15
+ if redis.exists(team_name)
16
+ redis.del(team_name)
17
+ response.reply(render_template(:team_deleted, team_name: team_name))
18
+ else
19
+ response.reply(render_template(:team_not_found, team_name: team_name))
20
+ end
21
+ end
22
+
23
+ Lita.register_handler(self)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ module Lita
2
+ module Handlers
3
+ class ListTeam < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(
8
+ /(\S*) team (list|show)/i,
9
+ :list,
10
+ command: true,
11
+ help: {
12
+ "<name> team list" => "list the people in the team",
13
+ "<name> team show" => "list the people in the team"
14
+ }
15
+ )
16
+
17
+ def list(response)
18
+ team_name = response.match_data[1]
19
+ if team = get_team(team_name)
20
+ response.reply(render_template(:list_team, team: team))
21
+ else
22
+ response.reply(render_template(:team_not_found, team_name: team_name))
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def get_team(team_name)
29
+ data = redis.get(team_name)
30
+ MultiJson.load(data, symbolize_keys: true) if data
31
+ end
32
+
33
+ Lita.register_handler(self)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module Lita
2
+ module Handlers
3
+ class ListTeams < Handler
4
+ namespace :team
5
+ template_root File.expand_path("../../../../templates", __FILE__)
6
+
7
+ route(
8
+ /list teams/i,
9
+ :list,
10
+ command: true,
11
+ help: {
12
+ "list teams" => "list all teams"
13
+ }
14
+ )
15
+
16
+ def list(response)
17
+ keys = redis.keys
18
+ if keys.empty?
19
+ response.reply t(:no_teams_has_been_created)
20
+ else
21
+ teams = redis.mget(redis.keys("*")).map(&parse)
22
+ response.reply render_template(:list_teams, teams: teams)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def parse
29
+ -> (team) { MultiJson.load(team, symbolize_keys: true) }
30
+ end
31
+
32
+ Lita.register_handler(self)
33
+ end
34
+ end
35
+ end