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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d99c55bb3b5b9a0bb971833d669d6e20f7c3832d334b75309285cb7ebe870baa
4
- data.tar.gz: '03248ecc10db6525d5a91d2327d397a7e5d3120af3fbb1d7782346831b28a5ee'
3
+ metadata.gz: 793302964e0e147e23fa2022f8a620009d0ddec4944df51c5aa0cf7c083260da
4
+ data.tar.gz: b6f0f7c2a4044e1526fb537311006c7b78565298989af22efec9b54e891209c6
5
5
  SHA512:
6
- metadata.gz: 2025525b45694117be1f29509ab9c934843a852fbce390b4678f2d8039aacfc064db6e93942a962187ab49de1dd1f4fec140ea28149893378bbb8da4309c3e29
7
- data.tar.gz: 3648058e784ff73c4bdf6e8b551648684f2d6db4a1ea2afd96f7a1845f888597a19e4cdc1ae8804129a9b7bd0c82d5fab0f020964a076e5c7d0a27532fe3ff3a
6
+ metadata.gz: 8f7d521a9ba7c9410018c331cbab8c8140bf334185ee1e266918262c55e5d29b2bac2bdb1f64b22473c44929e211a99676b3c7f3ad6d919f9625f360aa904117
7
+ data.tar.gz: 78bb318ff1a39dee34c1cf1a941d593a0e99c0ee2066bb897969cc16b6e53d9f0e4b11fcfeb919906ee0f30100f16aebcdd0a8ea172546008227a05a67ed7f1e
@@ -1,8 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## 0.3.2
3
+ ## 0.4.0
4
4
 
5
- - Add ticker to shell handler [Add ticker to shell handler by kinoppyd · Pull Request #8 · kinoppyd/repp](https://github.com/kinoppyd/repp/pull/8)
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
 
@@ -3,5 +3,6 @@ module Repp
3
3
  require 'repp/event/base'
4
4
  require 'repp/event/receive'
5
5
  require 'repp/event/ticker'
6
+ require 'repp/event/trigger'
6
7
  end
7
8
  end
@@ -21,7 +21,7 @@ module Repp
21
21
 
22
22
  class Base
23
23
  extend Attributes
24
- def initialize(params)
24
+ def initialize(params = {})
25
25
  @attributes = {}
26
26
  return unless params.respond_to?(:each_pair)
27
27
  params.each_pair do |k, v|
@@ -0,0 +1,8 @@
1
+ module Repp
2
+ module Event
3
+ class Trigger < Receive
4
+ event_type :trigger
5
+ interface :body, :payload, :original
6
+ end
7
+ end
8
+ end
@@ -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(type: :message, body: data, reply_to: reply_to, bot?: false)
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
@@ -26,33 +26,60 @@ module Repp
26
26
  end
27
27
 
28
28
  def handle
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
29
+ client.on :message do |message|
30
+ res, receive = process_message(message)
31
+ process_trigger(res, receive)
32
+ end
34
33
 
35
- receive = SlackReceive.new(
36
- body: data.text,
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
- 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'])
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
- res = app.call(receive)
48
- if res.first
49
- channel_to_post = res.last && res.last[:channel] || receive.channel
50
- attachments = res.last && res.last[:attachments]
51
- web_client.chat_postMessage(text: res.first, channel: channel_to_post, as_user: true, attachments: attachments)
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
 
@@ -1,3 +1,3 @@
1
1
  module Repp
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.2
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-29 00:00:00.000000000 Z
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