repp-heartful_slack 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
+ SHA256:
3
+ metadata.gz: 8df69d4de0c1e996c2908203e07f2243ba81710ae7945e639491b9f3a0855e56
4
+ data.tar.gz: 077debf0bbf19e0b6ff04ced3c657e8e75514ec7103779dc8d3bcbc729eedb14
5
+ SHA512:
6
+ metadata.gz: 53c30874967d90dc02024edf61da229db21e5475b8d2f3d3cf05639b8aaf788c41c04a516dcfec8c32f81b593835729d50792e1a6a8642157ed3a06413f7cb9e
7
+ data.tar.gz: 25dabfcea147a42f82f117033dac7bd1518190337e02cb2dec18a59b915930c7fb931a18eb89ada5e897d457c1a4bb1b03dc0de87ae3c38422278d1ddef97a33
@@ -0,0 +1,21 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Build and test with Rake
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rubocop
21
+ bundle exec rake
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,86 @@
1
+ AllCops:
2
+ Exclude:
3
+ - tmp/**/*
4
+ - vendor/**/*
5
+ TargetRubyVersion: 2.5
6
+ DisplayCopNames: true
7
+
8
+ # use japanese :)
9
+ Style/AsciiComments:
10
+ Enabled: false
11
+
12
+ # use method chain ( avoid use `end.compact` )
13
+ #
14
+ # hoge.map { |item|
15
+ # item.piyo
16
+ # }.compact
17
+ Style/BlockDelimiters:
18
+ Enabled: false
19
+
20
+ # no document
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ # use `!!hoge`
25
+ Style/DoubleNegation:
26
+ Enabled: false
27
+
28
+ # empty case is useful
29
+ #
30
+ # case
31
+ # when user.admin?
32
+ # ...
33
+ # when user.active?
34
+ # ...
35
+ # else
36
+ # ...
37
+ # end
38
+ Style/EmptyCaseCondition:
39
+ Enabled: false
40
+
41
+ # my preference :)
42
+ Style/EmptyMethod:
43
+ EnforcedStyle: expanded
44
+
45
+ # use `-> {}` syntax
46
+ Style/Lambda:
47
+ Enabled: false
48
+
49
+ # see Style/BlockDelimiters
50
+ Style/MultilineBlockChain:
51
+ Enabled: false
52
+
53
+ # I feel `.zero?` difficult to understand...
54
+ Style/NumericPredicate:
55
+ Enabled: false
56
+
57
+ # %w[a b c] or %i[a b c] ?
58
+ Style/SymbolArray:
59
+ Enabled: false
60
+
61
+ # incompatible DSL
62
+ Layout/EmptyLinesAroundArguments:
63
+ Enabled: false
64
+
65
+ # my preference :)
66
+ Layout/LineLength:
67
+ Max: 120
68
+
69
+ # :(
70
+ Metrics/AbcSize:
71
+ Max: 30
72
+
73
+ # incompatible DSL
74
+ Metrics/BlockLength:
75
+ Enabled: false
76
+
77
+ # incompatible DSL
78
+ Metrics/ClassLength:
79
+ Enabled: false
80
+
81
+ # my preference :(
82
+ Metrics/MethodLength:
83
+ Max: 25
84
+
85
+ Metrics/ParameterLists:
86
+ CountKeywordArgs: false
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in repp-heartful_slack.gemspec
8
+ gemspec
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ repp-heartful_slack (0.1.0)
5
+ repp
6
+ slack-ruby-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.2.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2)
17
+ ast (2.4.0)
18
+ concurrent-ruby (1.1.5)
19
+ eventmachine (1.2.7)
20
+ faraday (0.17.1)
21
+ multipart-post (>= 1.2, < 3)
22
+ faraday_middleware (0.13.1)
23
+ faraday (>= 0.7.4, < 1.0)
24
+ faye-websocket (0.10.9)
25
+ eventmachine (>= 0.12.0)
26
+ websocket-driver (>= 0.5.1)
27
+ gli (2.19.0)
28
+ hashie (4.0.0)
29
+ i18n (1.7.0)
30
+ concurrent-ruby (~> 1.0)
31
+ jaro_winkler (1.5.4)
32
+ minitest (5.13.0)
33
+ multipart-post (2.1.1)
34
+ parallel (1.19.1)
35
+ parser (2.6.5.0)
36
+ ast (~> 2.4.0)
37
+ power_assert (1.1.5)
38
+ rainbow (3.0.0)
39
+ rake (10.5.0)
40
+ repp (0.4.0)
41
+ concurrent-ruby (~> 1.0)
42
+ eventmachine (~> 1.2)
43
+ faye-websocket (~> 0.10)
44
+ slack-ruby-client (~> 0.11)
45
+ rubocop (0.78.0)
46
+ jaro_winkler (~> 1.5.1)
47
+ parallel (~> 1.10)
48
+ parser (>= 2.6)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ ruby-progressbar (~> 1.7)
51
+ unicode-display_width (>= 1.4.0, < 1.7)
52
+ ruby-progressbar (1.10.1)
53
+ slack-ruby-client (0.14.4)
54
+ activesupport
55
+ faraday (>= 0.9)
56
+ faraday_middleware
57
+ gli
58
+ hashie
59
+ websocket-driver
60
+ test-unit (3.3.4)
61
+ power_assert
62
+ thread_safe (0.3.6)
63
+ tzinfo (1.2.5)
64
+ thread_safe (~> 0.1)
65
+ unicode-display_width (1.6.0)
66
+ websocket-driver (0.7.1)
67
+ websocket-extensions (>= 0.1.0)
68
+ websocket-extensions (0.1.4)
69
+ zeitwerk (2.2.2)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler (~> 1.17)
76
+ rake (~> 10.0)
77
+ repp-heartful_slack!
78
+ rubocop (= 0.78.0)
79
+ test-unit (~> 3.3)
80
+
81
+ BUNDLED WITH
82
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 ru_shalm
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # repp-heartful_slack
2
+
3
+ > repp-heartful_slack is a powerful handler of [Repp](https://github.com/kinoppyd/repp) for [Slack](https://slack.com).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'repp-heartful_slack'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install repp-heartful_slack
20
+
21
+ ## Usage
22
+
23
+ in [Mobb](https://github.com/kinoppyd/mobb)
24
+
25
+ ```ruby
26
+ require 'mobb'
27
+ require 'repp/heartful_slack'
28
+
29
+ set :service, 'heartful_slack'
30
+
31
+ set :on_message do |_|
32
+ condition {@env.kind_of?(::Repp::HeartfulSlack::MessageReceive)}
33
+ end
34
+
35
+ set :on_event do |_|
36
+ condition {@env.kind_of?(::Repp::HeartfulSlack::EventReceive)}
37
+ end
38
+
39
+ set :to_notify do |_|
40
+ dest_condition do |res|
41
+ res.last[:channel] = ENV['NOTIFY_CHANNEL'] # ex. Cxxxxxxx
42
+ end
43
+ end
44
+
45
+ on 'emoji_changed', on_event: true, to_notify: true do
46
+ case @env.raw.subtype
47
+ when 'add'
48
+ "new emoji -> :#{@env.raw.name}:"
49
+ when 'remove'
50
+ "removed emoji -> #{@env.raw.names.map { |name| ":#{name}:" }.join(' ')}"
51
+ end
52
+ end
53
+ ```
54
+
55
+ see `sample/app.rb`
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = Dir['test/**/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'repp/heartful_slack'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,206 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'slack-ruby-client'
4
+
5
+ module Repp
6
+ module Handler
7
+ class HeartfulSlack
8
+ def initialize(app, options)
9
+ @app = app
10
+ @options = options
11
+ setup_token
12
+ end
13
+
14
+ def run
15
+ @application = @app.new
16
+ init_ticker
17
+ connect!
18
+ end
19
+
20
+ def stop
21
+ end
22
+
23
+ private
24
+
25
+ def setup_token
26
+ ::Slack.configure do |config|
27
+ config.token = ENV['SLACK_TOKEN']
28
+ end
29
+ end
30
+
31
+ def reset_client
32
+ @web_client = nil
33
+ @rtm_client = nil
34
+ @slack_service = nil
35
+ end
36
+
37
+ def web_client
38
+ @web_client ||= ::Slack::Web::Client.new
39
+ end
40
+
41
+ def rtm_client
42
+ @rtm_client ||= ::Slack::RealTime::Client.new
43
+ end
44
+
45
+ def init_ticker
46
+ @ticker = ::Repp::HeartfulSlack::Ticker.task(@application) do |res|
47
+ post_message(res)
48
+ end
49
+ @ticker.slack_service = slack_service
50
+ @ticker.run!
51
+ end
52
+
53
+ def connect!
54
+ reset_client
55
+ bind_events
56
+ @rtm_client.start!
57
+ rescue StandardError => e
58
+ puts e.inspect
59
+ sleep 1
60
+ end
61
+
62
+ def slack_service
63
+ @slack_service ||= ::Repp::HeartfulSlack::SlackService.new(web_client)
64
+ end
65
+
66
+ def bind_events
67
+ rtm_client.on :message, &method(:on_message)
68
+
69
+ %i[
70
+ bot_added
71
+ bot_changed
72
+ channel_archive
73
+ channel_created
74
+ channel_deleted
75
+ channel_rename
76
+ channel_unarchive
77
+ commands_changed
78
+ dnd_updated_user
79
+ emoji_changed
80
+ member_joined_channel
81
+ member_left_channel
82
+ pin_added
83
+ pin_removed
84
+ reaction_added
85
+ reaction_removed
86
+ subteam_created
87
+ subteam_members_changed
88
+ subteam_updated
89
+ team_join
90
+ user_change
91
+ ].each { |type| rtm_client.on type, &method(:on_event) }
92
+ end
93
+
94
+ def on_message(message)
95
+ return unless message.user
96
+
97
+ from_user = slack_service.find_user(message.user)
98
+ channel = slack_service.find_channel(message.channel)
99
+ reply_to = (message.text || '').scan(/<@(\w+?)>/).map do |node|
100
+ u = slack_service.find_user(node.first)
101
+ u ? u.name : nil
102
+ end
103
+
104
+ receive = ::Repp::HeartfulSlack::MessageReceive.new(
105
+ type: message.type,
106
+ body: format_text(message.text),
107
+ channel: channel,
108
+ user: from_user,
109
+ ts: message.ts,
110
+ reply_to: reply_to.compact,
111
+ raw: message,
112
+ slack_service: slack_service
113
+ )
114
+
115
+ process_receive(receive)
116
+ end
117
+
118
+ def on_event(message)
119
+ receive = ::Repp::HeartfulSlack::EventReceive.new(
120
+ type: message.type,
121
+ raw: message,
122
+ slack_service: slack_service
123
+ )
124
+ process_receive(receive)
125
+
126
+ case message.type
127
+ when 'channel_rename'
128
+ slack_service.refresh_channel_caches
129
+ when 'user_change'
130
+ slack_service.refresh_users_cache
131
+ end
132
+ end
133
+
134
+ def process_receive(receive)
135
+ res = @application.call(receive)
136
+ post_message(res, receive)
137
+ end
138
+
139
+ def post_message(res, receive = nil)
140
+ return unless res.first
141
+
142
+ channel_to_post = detect_channel_to_post(res, receive)
143
+ return unless channel_to_post
144
+
145
+ attachments = res.last && res.last[:attachments]
146
+
147
+ web_client.chat_postMessage(
148
+ text: res.first,
149
+ channel: channel_to_post,
150
+ as_user: true,
151
+ attachments: attachments
152
+ )
153
+ end
154
+
155
+ def detect_channel_to_post(res, receive = nil)
156
+ if res.last
157
+ res.last[:channel]
158
+ elsif receive
159
+ receive.channel&.id
160
+ end
161
+ end
162
+
163
+ def format_text(src_text)
164
+ text = src_text.to_s.dup
165
+ text.gsub!(/\\b/, '')
166
+ text.gsub!(/\<\@(U[^>\|]+)\>/) do
167
+ "@#{username_by_uid(Regexp.last_match(1))}"
168
+ end
169
+ text.gsub!(/\<\@(U[^\|]+)\|([^>]+)\>/) do
170
+ "@#{username_by_uid(Regexp.last_match(1))}"
171
+ end
172
+ text.gsub!(/\<\#(C[^>\|]+)\>/) do
173
+ c = slack_service.find_channel(Regexp.last_match(1))
174
+ "##{c ? c.name : c}"
175
+ end
176
+ text.gsub!(/\<\#(C[^\|]+)\|([^>]+)\>/) do
177
+ c = slack_service.find_channel(Regexp.last_match(1))
178
+ "##{c ? c.name : c}"
179
+ end
180
+ text.gsub!(/<[^\|>]+\|([^>]+)>/, '\1')
181
+ text.gsub!(/<|>/, '')
182
+ text.gsub!(/\!(here|channel|group)/, '@\1')
183
+ CGI.unescapeHTML(text)
184
+ end
185
+
186
+ def username_by_uid(uid)
187
+ user = slack_service.find_user(uid)
188
+ return uid unless user
189
+
190
+ if user.profile && !user.profile.display_name.to_s.empty?
191
+ user.profile.display_name
192
+ else
193
+ user.name
194
+ end
195
+ end
196
+
197
+ class << self
198
+ def run(app, options = {})
199
+ handler = HeartfulSlack.new(app, options)
200
+ yield handler if block_given?
201
+ handler.run
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'repp'
4
+ require 'repp/heartful_slack/version'
5
+ require 'repp/heartful_slack/event_receive'
6
+ require 'repp/heartful_slack/message_receive'
7
+ require 'repp/heartful_slack/slack_service'
8
+ require 'repp/heartful_slack/ticker'
9
+ require 'repp/heartful_slack/ticker_event'
10
+
11
+ module Repp
12
+ module Handler
13
+ autoload :HeartfulSlack, 'repp/handler/heartful_slack'
14
+ register 'heartful_slack', 'Repp::Handler::HeartfulSlack'
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Repp
4
+ module HeartfulSlack
5
+ class EventReceive < ::Repp::Event::Receive
6
+ interface :type, :raw, :slack_service
7
+
8
+ def body
9
+ type.to_s
10
+ end
11
+
12
+ def reply_to
13
+ []
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Repp
4
+ module HeartfulSlack
5
+ class MessageReceive < ::Repp::Event::Receive
6
+ interface :channel, :user, :type, :ts, :reply_to, :raw, :slack_service
7
+
8
+ def bot?
9
+ !!@is_bot
10
+ end
11
+
12
+ def bot=(switch)
13
+ @is_bot = switch
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Repp
4
+ module HeartfulSlack
5
+ class SlackService
6
+ attr_reader :web_client
7
+
8
+ def initialize(web_client)
9
+ @web_client = web_client
10
+ refresh
11
+ end
12
+
13
+ def refresh
14
+ refresh_users_cache
15
+ refresh_channel_caches
16
+ end
17
+
18
+ def refresh_users_cache
19
+ @user_caches = {}
20
+
21
+ resp = web_client.users_list
22
+ return unless resp.ok
23
+
24
+ resp.members.each do |member|
25
+ @user_caches[member.id] = member
26
+ end
27
+ end
28
+
29
+ def find_user(uid)
30
+ return @user_caches[uid] if @user_caches.key?(uid)
31
+
32
+ resp = web_client.users_info(user: uid)
33
+ @user_caches[uid] = resp.ok ? resp.user : nil
34
+ end
35
+
36
+ def refresh_channel_caches
37
+ @channel_caches = {}
38
+
39
+ resp = web_client.channels_list
40
+ return unless resp.ok
41
+
42
+ resp.channels.each do |channel|
43
+ @channel_caches[channel.id] = channel
44
+ end
45
+ end
46
+
47
+ def find_channel(uid)
48
+ return @channel_caches[uid] if @channel_caches.key?(uid)
49
+
50
+ resp = web_client.conversations_info(channel: uid)
51
+ return @channel_caches[uid] = resp.channel if resp.ok
52
+
53
+ resp = web_client.groups_info(channel: uid)
54
+ return @channel_caches[uid] = resp.group if resp.ok
55
+
56
+ @channel_caches[uid] = nil
57
+ end
58
+
59
+ def post(text:, channel:, attachments: [], as_user: true, name: nil, emoji: nil)
60
+ web_client.chat_postMessage({
61
+ text: text,
62
+ channel: channel,
63
+ as_user: as_user,
64
+ username: name,
65
+ icon_emoji: ":#{emoji}:",
66
+ attachments: attachments
67
+ }.delete_if { |_, v| v.nil? })
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Repp
4
+ module HeartfulSlack
5
+ class Ticker < ::Repp::Ticker
6
+ attr_accessor :slack_service
7
+
8
+ def run!
9
+ @task = Concurrent::TimerTask.new(execution_interval: 1) do
10
+ next unless slack_service
11
+
12
+ @block.call(Task.new.tick(TickerEvent.new(
13
+ body: Time.now,
14
+ slack_service: slack_service
15
+ )))
16
+ end
17
+ @task.execute
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Repp
4
+ module HeartfulSlack
5
+ class TickerEvent < ::Repp::Event::Ticker
6
+ interface :slack_service
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Repp
4
+ module HeartfulSlack
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'repp/heartful_slack/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'repp-heartful_slack'
9
+ spec.version = Repp::HeartfulSlack::VERSION
10
+ spec.authors = ['ru_shalm']
11
+ spec.email = ['ru_shalm@hazimu.com']
12
+
13
+ spec.summary = 'repp-heartful_slack is a powerful handler of Repp for Slack.'
14
+ spec.homepage = 'https://github.com/rutan/repp-heartful_slack'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'repp'
25
+ spec.add_dependency 'slack-ruby-client'
26
+ spec.add_development_dependency 'bundler', '~> 1.17'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop', '0.78.0'
29
+ spec.add_development_dependency 'test-unit', '~> 3.3'
30
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gem 'mobb', '~> 0.5.1'
8
+ gem 'repp-heartful_slack', path: '..'
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ repp-heartful_slack (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.0.2.1)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ zeitwerk (~> 2.2)
15
+ chronic (0.10.2)
16
+ concurrent-ruby (1.1.5)
17
+ eventmachine (1.2.7)
18
+ faraday (0.17.1)
19
+ multipart-post (>= 1.2, < 3)
20
+ faraday_middleware (0.13.1)
21
+ faraday (>= 0.7.4, < 1.0)
22
+ faye-websocket (0.10.9)
23
+ eventmachine (>= 0.12.0)
24
+ websocket-driver (>= 0.5.1)
25
+ gli (2.19.0)
26
+ hashie (4.0.0)
27
+ i18n (1.7.0)
28
+ concurrent-ruby (~> 1.0)
29
+ minitest (5.13.0)
30
+ mobb (0.5.1)
31
+ parse-cron (~> 0.1)
32
+ repp (~> 0.4)
33
+ whenever (~> 0.10)
34
+ multipart-post (2.1.1)
35
+ parse-cron (0.1.4)
36
+ repp (0.4.0)
37
+ concurrent-ruby (~> 1.0)
38
+ eventmachine (~> 1.2)
39
+ faye-websocket (~> 0.10)
40
+ slack-ruby-client (~> 0.11)
41
+ slack-ruby-client (0.14.4)
42
+ activesupport
43
+ faraday (>= 0.9)
44
+ faraday_middleware
45
+ gli
46
+ hashie
47
+ websocket-driver
48
+ thread_safe (0.3.6)
49
+ tzinfo (1.2.5)
50
+ thread_safe (~> 0.1)
51
+ websocket-driver (0.7.1)
52
+ websocket-extensions (>= 0.1.0)
53
+ websocket-extensions (0.1.4)
54
+ whenever (0.11.0)
55
+ chronic (>= 0.6.3)
56
+ zeitwerk (2.2.2)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ mobb (~> 0.5.1)
63
+ repp-heartful_slack!
64
+
65
+ BUNDLED WITH
66
+ 1.17.2
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mobb'
4
+ require 'repp/heartful_slack'
5
+
6
+ set :service, 'heartful_slack'
7
+
8
+ set :on_message do |_|
9
+ condition { @env.is_a?(::Repp::HeartfulSlack::MessageReceive) }
10
+ end
11
+
12
+ set :on_event do |_|
13
+ condition { @env.is_a?(::Repp::HeartfulSlack::EventReceive) }
14
+ end
15
+
16
+ set :to_notify do |_|
17
+ dest_condition do |res|
18
+ res.last[:channel] = ENV['NOTIFY_CHANNEL'] # ex. Cxxxxxxx
19
+ end
20
+ end
21
+
22
+ on 'ping', on_message: true do
23
+ 'pong'
24
+ end
25
+
26
+ on 'channel_archive', on_event: true, to_notify: true do
27
+ channel = @env.slack_service.find_channel(@env.raw.channel)
28
+ "archive -> <##{channel.id}>"
29
+ end
30
+
31
+ on 'channel_created', on_event: true, to_notify: true do
32
+ "created -> <##{@env.raw.channel.id}>"
33
+ end
34
+
35
+ on 'channel_deleted', on_event: true, to_notify: true do
36
+ channel = @env.slack_service.find_channel(@env.raw.channel)
37
+ next unless channel
38
+
39
+ "deleted -> `##{channel.name}`"
40
+ end
41
+
42
+ on 'channel_rename', on_event: true, to_notify: true do
43
+ old_name = @env.slack_service.find_channel(@env.raw.channel.id)&.name
44
+ "rename `#{old_name}` -> <##{@env.raw.channel.id}>"
45
+ end
46
+
47
+ on 'channel_unarchive', on_event: true, to_notify: true do
48
+ channel = @env.slack_service.find_channel(@env.raw.channel)
49
+ "unarchive -> <##{channel.id}>"
50
+ end
51
+
52
+ on 'emoji_changed', on_event: true, to_notify: true do
53
+ case @env.raw.subtype
54
+ when 'add'
55
+ "new emoji -> :#{@env.raw.name}:"
56
+ when 'remove'
57
+ "removed emoji -> #{@env.raw.names.map { |name| ":#{name}:" }.join(' ')}"
58
+ end
59
+ end
60
+
61
+ on 'subteam_created', on_event: true, to_notify: true do
62
+ "new subteam: #{@env.raw.subteam.handle}"
63
+ end
64
+
65
+ on 'team_join', on_event: true, to_notify: true do
66
+ "new member -> <#{@env.raw.user.id}>"
67
+ end
68
+
69
+ on 'user_change', on_event: true, to_notify: true do
70
+ old_user = @env.slack_service.find_user(@env.raw.user.id)
71
+ if @env.raw.user.deleted != old_user.deleted
72
+ if @env.raw.user.deleted
73
+ "zuttomo member -> <#{@env.raw.user.id}>"
74
+ else
75
+ "reactivate member -> <#{@env.raw.user.id}>"
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repp-heartful_slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ru_shalm
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: repp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.78.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.78.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
97
+ description:
98
+ email:
99
+ - ru_shalm@hazimu.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".github/workflows/ruby.yml"
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/repp/handler/heartful_slack.rb
115
+ - lib/repp/heartful_slack.rb
116
+ - lib/repp/heartful_slack/event_receive.rb
117
+ - lib/repp/heartful_slack/message_receive.rb
118
+ - lib/repp/heartful_slack/slack_service.rb
119
+ - lib/repp/heartful_slack/ticker.rb
120
+ - lib/repp/heartful_slack/ticker_event.rb
121
+ - lib/repp/heartful_slack/version.rb
122
+ - repp-heartful_slack.gemspec
123
+ - sample/Gemfile
124
+ - sample/Gemfile.lock
125
+ - sample/app.rb
126
+ homepage: https://github.com/rutan/repp-heartful_slack
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.0.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: repp-heartful_slack is a powerful handler of Repp for Slack.
149
+ test_files: []