lita-slack-status 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: 6b4667151e40bae3cacf0783825230fbe21cd326
4
+ data.tar.gz: a6e99a0a12a79ea0aac37db067ed47f0d497680d
5
+ SHA512:
6
+ metadata.gz: 1b23b61d271c12075341ff44d6dcf66d617db42185852f9d82fb5f6b2cd3f9fe647263fa713ad99f2e5ea25f840f080ef8186419f740972dcba17f27f94014fb
7
+ data.tar.gz: 3f9595c73ad72fe95b00f41d6bd69fdd8583cae0014c5743cb1b88f82519f90ee69a1f403063d88c5b00c90428cb388d12e0f88bf227471fd691f61893ccc093
@@ -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
+ lita_config.rb
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'lita-slack'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Atsuo Fukaya
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,36 @@
1
+ # lita-slack-status
2
+
3
+ ## Installation
4
+
5
+ Add lita-slack-status to your Lita instance's Gemfile:
6
+
7
+ ``` ruby
8
+ gem "lita-slack-status"
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```ruby
14
+ Lita.configure do |config|
15
+ # admin token are require to update users profile
16
+ # https://api.slack.com/custom-integrations/legacy-tokens
17
+ config.handlers.slack_status.admin_slack_token = ENV["ADMIN_SLACK_TOKEN"]
18
+ end
19
+
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```
25
+ status save foo :sushi: eating sushi
26
+ status set foo
27
+ status list
28
+ ```
29
+
30
+ OR
31
+
32
+ ```
33
+ sss foo :sushi: eating sushi
34
+ ss foo
35
+ sl
36
+ ```
@@ -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/slack_status"
8
+
9
+ Lita::Handlers::SlackStatus.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,103 @@
1
+ require 'lita-slack'
2
+ require 'slack-ruby-client'
3
+
4
+ module Lita
5
+ module Handlers
6
+ class SlackStatus < Handler
7
+ route /^s(?:tatus)? ?save (\S+) (:.+:)(?: (.+))?$/, :save,
8
+ help: { 'status save [name] [emoji] [text(optional)]' => 'save status' }
9
+ route /^sss (\S+) (:.+:)(?: (.+))?$/, :save_and_set,
10
+ help: { 'sss [name] [emoji] [text(optional)]' => 'save status and set(sss)' }
11
+ route /^s(?:tatus)? ?rename (\S+) (\S+)$/, :rename,
12
+ help: { 'status rename [from] [to]' => 'rename status' }
13
+ route /^s(?:tatus)? ?delete (\S+)$/, :delete,
14
+ help: { 'status delete [name]' => 'delete status' }
15
+ route /^s(?:tatus)? ?l(?:ist)?$/, :list,
16
+ help: { 'status list' => 'list status' }
17
+ route /^s(?:tatus)? ?s(?:et)? (\S+)(?: (.+))?$/, :set,
18
+ help: { 'status set [name] [text(optional)]' => 'set status' }
19
+ route /^s(?:tatus)? ?c(?:lear)?$/, :clear,
20
+ help: { 'status clear' => 'clear status' }
21
+
22
+ config :admin_slack_token, required: true
23
+
24
+ def save(response)
25
+ name, emoji, text = response.matches.flatten
26
+ redis.hset("users/#{response.user.id}/statuses", name, {emoji: emoji, text: text}.to_json)
27
+ response.reply 'ok'
28
+ end
29
+
30
+ def save_and_set(response)
31
+ name, emoji, text = response.matches.flatten
32
+ redis.hset("users/#{response.user.id}/statuses", name, {emoji: emoji, text: text}.to_json)
33
+
34
+ response.reply set_profile(response.user.id, emoji: emoji, text: text)
35
+ end
36
+
37
+ def list(response)
38
+ statuses = redis.hgetall("users/#{response.user.id}/statuses")
39
+ return response.reply '(empty)' if statuses.empty?
40
+
41
+ message = statuses.map do |name, status_json|
42
+ status = JSON.parse(status_json)
43
+ status_str = [status['emoji'], status['text']].compact.join(' ')
44
+ "#{name} => #{status_str} (`#{name} #{status_str}`)"
45
+ end.join("\n")
46
+
47
+ response.reply message
48
+ end
49
+
50
+ def delete(response)
51
+ name = response.matches.flatten.first
52
+ if redis.hdel("users/#{response.user.id}/statuses", name) == 1
53
+ response.reply 'ok'
54
+ else
55
+ response.reply "not found: #{name}"
56
+ end
57
+ end
58
+
59
+ def rename(response)
60
+ from_name, to_name = response.matches.flatten
61
+ status_json = redis.hget("users/#{response.user.id}/statuses", from_name)
62
+ return response.reply "not found: #{name}" unless status_json
63
+
64
+ redis.hset("users/#{response.user.id}/statuses", to_name, status_json)
65
+ redis.hdel("users/#{response.user.id}/statuses", from_name)
66
+ response.reply 'ok'
67
+ end
68
+
69
+ def set(response)
70
+ name, text = response.matches.flatten
71
+ status_json = redis.hget("users/#{response.user.id}/statuses", name)
72
+ return response.reply "not found: #{name}" unless status_json
73
+
74
+ status = JSON.parse(status_json)
75
+
76
+ response.reply set_profile(response.user.id, emoji: status['emoji'], text: text || status['text'])
77
+ end
78
+
79
+ def clear(response)
80
+ response.reply set_profile(response.user.id, emoji: nil, text: nil)
81
+ end
82
+
83
+ private
84
+
85
+ def set_profile(user_id, emoji: , text:)
86
+ resp = slack_client.users_profile_set(
87
+ user: user_id,
88
+ profile: {
89
+ status_emoji: emoji.to_s,
90
+ status_text: text.to_s
91
+ }.to_json
92
+ )
93
+ resp['ok'] ? 'ok' : "error: #{resp['error']}"
94
+ end
95
+
96
+ def slack_client
97
+ @slack_client ||= Slack::Web::Client.new(token: config.admin_slack_token)
98
+ end
99
+
100
+ Lita.register_handler(self)
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-slack-status"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["fukayatsu"]
5
+ spec.email = ["fukayatsu@gmail.com"]
6
+ spec.description = "Lita handler to manage slack statuses"
7
+ spec.summary = "Lita handler to manage slack statuses"
8
+ spec.homepage = "https://github.com/fukayatsu/lita-slack-status"
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.7"
18
+ spec.add_runtime_dependency "slack-ruby-client", ">= 0.8.1"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "pry-byebug"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rack-test"
24
+ spec.add_development_dependency "rspec", ">= 3.0.0"
25
+ end
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ slack_status:
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::SlackStatus, lita_handler: true do
4
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-slack-status"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-slack-status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fukayatsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-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.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-ruby-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
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: rake
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: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ description: Lita handler to manage slack statuses
112
+ email:
113
+ - fukayatsu@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/lita-slack-status.rb
124
+ - lib/lita/handlers/slack_status.rb
125
+ - lita-slack-status.gemspec
126
+ - locales/en.yml
127
+ - spec/lita/handlers/slack_status_spec.rb
128
+ - spec/spec_helper.rb
129
+ - templates/.gitkeep
130
+ homepage: https://github.com/fukayatsu/lita-slack-status
131
+ licenses:
132
+ - MIT
133
+ metadata:
134
+ lita_plugin_type: handler
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.6.11
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Lita handler to manage slack statuses
155
+ test_files:
156
+ - spec/lita/handlers/slack_status_spec.rb
157
+ - spec/spec_helper.rb