repp 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -2
- data/lib/repp/event.rb +1 -0
- data/lib/repp/event/base.rb +1 -1
- data/lib/repp/event/trigger.rb +8 -0
- data/lib/repp/handler/shell.rb +21 -2
- data/lib/repp/handler/slack.rb +49 -22
- data/lib/repp/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 793302964e0e147e23fa2022f8a620009d0ddec4944df51c5aa0cf7c083260da
|
4
|
+
data.tar.gz: b6f0f7c2a4044e1526fb537311006c7b78565298989af22efec9b54e891209c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f7d521a9ba7c9410018c331cbab8c8140bf334185ee1e266918262c55e5d29b2bac2bdb1f64b22473c44929e211a99676b3c7f3ad6d919f9625f360aa904117
|
7
|
+
data.tar.gz: 78bb318ff1a39dee34c1cf1a941d593a0e99c0ee2066bb897969cc16b6e53d9f0e4b11fcfeb919906ee0f30100f16aebcdd0a8ea172546008227a05a67ed7f1e
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.4.0
|
4
4
|
|
5
|
-
- Add
|
5
|
+
- Add Trigger handler [#10](https://github.com/kinoppyd/repp/pull/10)
|
6
|
+
- Set detail user data to receive object in Slack handler [#9](https://github.com/kinoppyd/repp/pull/9)
|
7
|
+
- Add ticker to shell handler [#8](https://github.com/kinoppyd/repp/pull/8)
|
6
8
|
|
7
9
|
## 0.3.1
|
8
10
|
|
data/lib/repp/event.rb
CHANGED
data/lib/repp/event/base.rb
CHANGED
data/lib/repp/handler/shell.rb
CHANGED
@@ -8,11 +8,30 @@ module Repp
|
|
8
8
|
def initialize(app) @app = app; end
|
9
9
|
def receive_line(data)
|
10
10
|
reply_to = /@\w+/.match(data)&.[](1)
|
11
|
-
message = Event::Receive.new(
|
11
|
+
message = Event::Receive.new(body: data, reply_to: reply_to, bot?: false)
|
12
|
+
res = process_message(message)
|
13
|
+
process_trigger(res, message)
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_message(message)
|
12
17
|
res = @app.call(message)
|
13
18
|
if res.any?
|
14
19
|
$stdout.puts res.first
|
15
20
|
end
|
21
|
+
res
|
22
|
+
end
|
23
|
+
|
24
|
+
def process_trigger(res, message)
|
25
|
+
if res[1][:trigger]
|
26
|
+
payload = res[1][:trigger][:payload]
|
27
|
+
res[1][:trigger][:names].each do |name|
|
28
|
+
trigger = Event::Trigger.new(body: name, payload: payload, original: message)
|
29
|
+
Thread.new do
|
30
|
+
trigger_res = process_message(trigger)
|
31
|
+
process_trigger(trigger_res, message)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
16
35
|
end
|
17
36
|
end
|
18
37
|
|
@@ -21,7 +40,7 @@ module Repp
|
|
21
40
|
|
22
41
|
application = app.new
|
23
42
|
@ticker = Ticker.task(application) do |res|
|
24
|
-
if res.any?
|
43
|
+
if res.any? && res.first
|
25
44
|
$stdout.puts res.first
|
26
45
|
end
|
27
46
|
end
|
data/lib/repp/handler/slack.rb
CHANGED
@@ -26,33 +26,60 @@ module Repp
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def handle
|
29
|
-
client.on :message do |
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
29
|
+
client.on :message do |message|
|
30
|
+
res, receive = process_message(message)
|
31
|
+
process_trigger(res, receive)
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
channel: data.channel,
|
38
|
-
user: data.user,
|
39
|
-
type: data.type,
|
40
|
-
ts: data.ts,
|
41
|
-
reply_to: reply_to.compact
|
42
|
-
)
|
34
|
+
client.start!
|
35
|
+
end
|
43
36
|
|
44
|
-
|
45
|
-
|
37
|
+
def process_message(message)
|
38
|
+
receive = if message.instance_of?(Event::Trigger)
|
39
|
+
message
|
40
|
+
else
|
41
|
+
reply_to = (message.text || "").scan(REPLY_REGEXP).map do |node|
|
42
|
+
user = users.find { |u| u.id == node.first }
|
43
|
+
user ? user.name : nil
|
44
|
+
end
|
45
|
+
|
46
|
+
from_user = users.find { |u| u.id == message.user } || users(true).find { |u| u.id == message.user }
|
47
|
+
|
48
|
+
receive = SlackReceive.new(
|
49
|
+
body: message.text,
|
50
|
+
channel: message.channel,
|
51
|
+
user: from_user,
|
52
|
+
type: message.type,
|
53
|
+
ts: message.ts,
|
54
|
+
reply_to: reply_to.compact
|
55
|
+
)
|
56
|
+
|
57
|
+
receive.bot = (message['subtype'] == 'bot_message' || from_user.nil? || from_user['is_bot'])
|
58
|
+
receive
|
59
|
+
end
|
60
|
+
|
61
|
+
res = app.call(receive)
|
62
|
+
|
63
|
+
receive = message.original if message.instance_of?(Event::Trigger)
|
64
|
+
if res.first
|
65
|
+
channel_to_post = res.last && res.last[:channel] || receive.channel
|
66
|
+
attachments = res.last && res.last[:attachments]
|
67
|
+
web_client.chat_postMessage(text: res.first, channel: channel_to_post, as_user: true, attachments: attachments)
|
68
|
+
end
|
69
|
+
[res, receive]
|
70
|
+
end
|
46
71
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
72
|
+
def process_trigger(res, receive)
|
73
|
+
if res[1][:trigger]
|
74
|
+
payload = res[1][:trigger][:payload]
|
75
|
+
res[1][:trigger][:names].each do |name|
|
76
|
+
trigger = Event::Trigger.new(body: name, payload: payload, original: receive)
|
77
|
+
Thread.new do
|
78
|
+
trigger_res, _ = process_message(trigger)
|
79
|
+
process_trigger(trigger_res, receive)
|
80
|
+
end
|
52
81
|
end
|
53
82
|
end
|
54
|
-
|
55
|
-
client.start!
|
56
83
|
end
|
57
84
|
end
|
58
85
|
|
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.4.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-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/repp/event/base.rb
|
129
129
|
- lib/repp/event/receive.rb
|
130
130
|
- lib/repp/event/ticker.rb
|
131
|
+
- lib/repp/event/trigger.rb
|
131
132
|
- lib/repp/handler.rb
|
132
133
|
- lib/repp/handler/shell.rb
|
133
134
|
- lib/repp/handler/slack.rb
|