repp 0.2.0 → 0.3.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: 95bb3f7cd6e674913e4c9c9862570ad84360922e70e6b0c610292c3fa63346f4
4
- data.tar.gz: 64aaf03c29c5a7d561aa0bfd4f49575ee32dd03a78e433651bb306d46a921ff7
3
+ metadata.gz: 2e3c9fcf4aecdd0f0e0445d854b0492b89eba86d71ce0fc7d4995c59663ce267
4
+ data.tar.gz: 7bc30cfdbc22ceba44b53d08af8a7116c34fdf43232a4bc721aa9c756c00cb5c
5
5
  SHA512:
6
- metadata.gz: 5ae22b70a81277b959555c5851ac0623a5e6f68a3ea3cc25d4ad9d1fa4f35357981fbb945e382968e7620e483fe50795857e4549b33dc6baa5cd6ee813ed3312
7
- data.tar.gz: 712527ac39e00ff3dbcbdfa8ac66e557e8a768a86cdea43a41fa3b45394cd39acc68d61f3ffd6d2e732d5d08761d87936ae798521d8a714b4c85881a9199d3ad
6
+ metadata.gz: 6d941084b8fc8f4de2476c33215470e493b7c32c324ee63e7be38cd36d1663a1ba66ef32f3279456aae14925523773dd77cdb332d9e66e2522eb77622b93af31
7
+ data.tar.gz: ed6e768bc83262116b4148409b40a6b6ce8297fe3232fcc28f821c9a476a01b91827f0b5c551de6d2217719d2b778f4ac443dceb765f74fba23588685e2ff4d0
data/lib/repp.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "repp/version"
2
2
  require "repp/event"
3
3
  require 'repp/handler'
4
+ require 'repp/ticker'
@@ -2,7 +2,7 @@ module Repp
2
2
  module Event
3
3
  class Ticker < Base
4
4
  event_type :ticker
5
- interface :body, :reply_to, :bot?
5
+ interface :body
6
6
  end
7
7
  end
8
8
  end
@@ -27,7 +27,7 @@ module Repp
27
27
 
28
28
  def handle
29
29
  client.on :message do |data|
30
- reply_to = data.text.scan(REPLY_REGEXP).map do |node|
30
+ reply_to = (data.text || "").scan(REPLY_REGEXP).map do |node|
31
31
  user = users.find { |u| u.id == node.first }
32
32
  user ? user.name : nil
33
33
  end
@@ -64,7 +64,22 @@ module Repp
64
64
  end
65
65
  @client = ::Slack::RealTime::Client.new
66
66
  @web_client = ::Slack::Web::Client.new
67
- handler = SlackMessageHandler.new(@client, @web_client, app.new)
67
+
68
+ application = app.new
69
+ @ticker = Ticker.task(application) do |res|
70
+ if res.first
71
+ if res.last && res.last[:dest_channel]
72
+ channel_to_post = res.last[:dest_channel]
73
+ @web_client.chat_postMessage(text: res.first, channel: channel_to_post, as_user: true)
74
+ else
75
+ message = "Need 'dest_to:' option to every or cron job like:\n" +
76
+ "every 1.hour, dest_to: 'channel_name' do"
77
+ $stderr.puts(message)
78
+ end
79
+ end
80
+ end
81
+ @ticker.run!
82
+ handler = SlackMessageHandler.new(@client, @web_client, application)
68
83
  handler.handle
69
84
  end
70
85
 
@@ -0,0 +1,33 @@
1
+ require 'concurrent'
2
+ module Repp
3
+ class Ticker
4
+ def self.task(app, &block)
5
+ Task.app = app
6
+ new(&block)
7
+ end
8
+
9
+ class Task
10
+ include Concurrent::Async
11
+
12
+ class << self
13
+ def app=(app); @app = app end
14
+ def app; @app end
15
+ end
16
+
17
+ def tick(event)
18
+ Task.app.call(event)
19
+ end
20
+ end
21
+
22
+ def initialize(&block)
23
+ @block = block
24
+ end
25
+
26
+ def run!
27
+ @task = Concurrent::TimerTask.new(execution_interval: 1) do
28
+ @block.call(Task.new.tick(Event::Ticker.new(body: Time.now)))
29
+ end
30
+ @task.execute
31
+ end
32
+ end
33
+ end
data/lib/repp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Repp
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/repp.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "eventmachine", "~> 1.2"
25
25
  spec.add_dependency "slack-ruby-client", "~> 0.11"
26
26
  spec.add_dependency "faye-websocket", "~> 0.10"
27
+ spec.add_dependency "concurrent-ruby", "~> 1.0"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.16"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
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.2.0
4
+ version: 0.3.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-08-26 00:00:00.000000000 Z
11
+ date: 2018-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: concurrent-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +130,7 @@ files:
116
130
  - lib/repp/handler.rb
117
131
  - lib/repp/handler/shell.rb
118
132
  - lib/repp/handler/slack.rb
133
+ - lib/repp/ticker.rb
119
134
  - lib/repp/version.rb
120
135
  - repp.gemspec
121
136
  homepage: https://github.com/kinoppyd/repp