repp 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/repp/handler/slack.rb +36 -7
- data/lib/repp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95bb3f7cd6e674913e4c9c9862570ad84360922e70e6b0c610292c3fa63346f4
|
4
|
+
data.tar.gz: 64aaf03c29c5a7d561aa0bfd4f49575ee32dd03a78e433651bb306d46a921ff7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ae22b70a81277b959555c5851ac0623a5e6f68a3ea3cc25d4ad9d1fa4f35357981fbb945e382968e7620e483fe50795857e4549b33dc6baa5cd6ee813ed3312
|
7
|
+
data.tar.gz: 712527ac39e00ff3dbcbdfa8ac66e557e8a768a86cdea43a41fa3b45394cd39acc68d61f3ffd6d2e732d5d08761d87936ae798521d8a714b4c85881a9199d3ad
|
data/lib/repp/handler/slack.rb
CHANGED
@@ -3,26 +3,55 @@ module Repp
|
|
3
3
|
class Slack
|
4
4
|
require 'slack-ruby-client'
|
5
5
|
|
6
|
+
REPLY_REGEXP = /<@(\w+?)>/
|
7
|
+
|
6
8
|
class SlackReceive < Event::Receive
|
7
|
-
interface :channel, :user, :type, :ts
|
9
|
+
interface :channel, :user, :type, :ts, :reply_to
|
10
|
+
|
11
|
+
def bot?; !!@is_bot; end
|
12
|
+
def bot=(switch); @is_bot = switch; end
|
8
13
|
end
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
class SlackMessageHandler
|
16
|
+
attr_reader :client, :web_client, :app
|
17
|
+
def initialize(client, web_client, app)
|
18
|
+
@client = client
|
19
|
+
@web_client = web_client
|
20
|
+
@app = app
|
21
|
+
end
|
22
|
+
|
23
|
+
def users(refresh = false)
|
24
|
+
@users = @web_client.list_users.members if refresh
|
25
|
+
@users ||= @web_client.users_list.members
|
26
|
+
end
|
27
|
+
|
28
|
+
def handle
|
12
29
|
client.on :message do |data|
|
30
|
+
reply_to = data.text.scan(REPLY_REGEXP).map do |node|
|
31
|
+
user = users.find { |u| u.id == node.first }
|
32
|
+
user ? user.name : nil
|
33
|
+
end
|
34
|
+
|
13
35
|
receive = SlackReceive.new(
|
14
36
|
body: data.text,
|
15
37
|
channel: data.channel,
|
16
38
|
user: data.user,
|
17
39
|
type: data.type,
|
18
|
-
ts: data.ts
|
40
|
+
ts: data.ts,
|
41
|
+
reply_to: reply_to.compact
|
19
42
|
)
|
43
|
+
|
44
|
+
user = users.find { |u| u.id == data.user } || users(true).find { |u| u.id == data.user }
|
45
|
+
receive.bot = (data['subtype'] == 'bot_message' || user.nil? || user['is_bot'])
|
46
|
+
|
20
47
|
res = app.call(receive)
|
21
48
|
if res.first
|
22
|
-
channel_to_post = res.last
|
49
|
+
channel_to_post = res.last.nil? ? receive.channel : res.last[:channel]
|
23
50
|
web_client.chat_postMessage(text: res.first, channel: channel_to_post, as_user: true)
|
24
51
|
end
|
25
52
|
end
|
53
|
+
|
54
|
+
client.start!
|
26
55
|
end
|
27
56
|
end
|
28
57
|
|
@@ -35,8 +64,8 @@ module Repp
|
|
35
64
|
end
|
36
65
|
@client = ::Slack::RealTime::Client.new
|
37
66
|
@web_client = ::Slack::Web::Client.new
|
38
|
-
SlackMessageHandler.
|
39
|
-
|
67
|
+
handler = SlackMessageHandler.new(@client, @web_client, app.new)
|
68
|
+
handler.handle
|
40
69
|
end
|
41
70
|
|
42
71
|
def stop!
|
data/lib/repp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kinoppyd
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|