slappy 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/slappy/client.rb +9 -2
- data/lib/slappy/concerns/debuggable.rb +12 -0
- data/lib/slappy/listeners/concerns/listenable.rb +16 -3
- data/lib/slappy/schedule.rb +18 -8
- data/lib/slappy/version.rb +1 -1
- data/lib/slappy.rb +1 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cda9ebb75413427151ae533a04d020a9e9db638
|
4
|
+
data.tar.gz: 582468f8b8eb1760fceb92b3b26f6dd83aa07957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85575d21f7b3e1c04d65f9a685e133eeb941e42e8bdffbe5637690be61c09f7e9995d0cc963f1c63a6db035ee3b55c2d7e98218f209f93432ae0575e1c9cd971
|
7
|
+
data.tar.gz: 526f35c3436c164a3df4846a7a3641a5107130b04d8c8f204191c666d9cca1e10de4d6837e9b0dad265bee7eb6a20ac20f458f9e1f3eec9060db13647e83455a
|
data/README.md
CHANGED
data/lib/slappy/client.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Slappy
|
2
2
|
class Client
|
3
|
+
include Slappy::Debuggable
|
4
|
+
|
3
5
|
attr_reader :start_time
|
4
6
|
|
5
7
|
def initialize
|
@@ -17,22 +19,26 @@ module Slappy
|
|
17
19
|
register_event event_name, listeners
|
18
20
|
end
|
19
21
|
set_signal_trap
|
22
|
+
Debug.log 'Slappy start'
|
20
23
|
client.start
|
21
24
|
end
|
22
25
|
|
23
26
|
def hello(&block)
|
24
27
|
@callbacks[:hello] ||= []
|
25
28
|
@callbacks[:hello].push block
|
29
|
+
Debug.log "Add hello event(#{@callbacks[:hello].size})"
|
26
30
|
end
|
27
31
|
|
28
32
|
def hear(pattern, &block)
|
29
33
|
@callbacks[:message] ||= []
|
30
34
|
@callbacks[:message].push Listener::TextListener.new(pattern, block)
|
35
|
+
Debug.log "Add here event(#{@callbacks[:message].size}): #{pattern}"
|
31
36
|
end
|
32
37
|
|
33
38
|
def monitor(type, &block)
|
34
39
|
@callbacks[type.to_sym] ||= []
|
35
40
|
@callbacks[type.to_sym].push Listener::TypeListener.new(type, block)
|
41
|
+
Debug.log "Add monitor event(#{@callbacks[type.to_sym].size}): #{type}"
|
36
42
|
end
|
37
43
|
|
38
44
|
def say(text, options = {})
|
@@ -40,9 +46,10 @@ module Slappy
|
|
40
46
|
Messanger.new(options).message
|
41
47
|
end
|
42
48
|
|
43
|
-
def schedule(
|
49
|
+
def schedule(pattern, options = {}, &block)
|
44
50
|
@schedule ||= Schedule.new
|
45
|
-
@schedule.register
|
51
|
+
@schedule.register pattern, options, &block
|
52
|
+
Debug.log "Add schedule event(#{@schedule.list.size}): #{pattern}"
|
46
53
|
end
|
47
54
|
|
48
55
|
private
|
@@ -2,6 +2,7 @@ module Slappy
|
|
2
2
|
module Listener
|
3
3
|
module Listenable
|
4
4
|
include ActiveSupport::Concern
|
5
|
+
include Slappy::Debuggable
|
5
6
|
|
6
7
|
attr_reader :pattern
|
7
8
|
|
@@ -11,14 +12,26 @@ module Slappy
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def call(event)
|
14
|
-
|
15
|
+
Debug.log "Listen event call: #{target_element}:#{event.send(target_element)}"
|
16
|
+
|
17
|
+
unless time_valid?(event)
|
18
|
+
Debug.log 'Event happend in before start time'
|
19
|
+
return
|
20
|
+
end
|
15
21
|
|
16
22
|
target = event.send(target_element)
|
17
|
-
|
23
|
+
unless target
|
24
|
+
Debug.log 'Target is nil'
|
25
|
+
return
|
26
|
+
end
|
18
27
|
|
19
28
|
event.matches = target.match pattern
|
20
|
-
|
29
|
+
unless event.matches
|
30
|
+
Debug.log "Target is not match pattern(#{pattern})"
|
31
|
+
return
|
32
|
+
end
|
21
33
|
|
34
|
+
Debug.log "Callback event call: #{pattern}"
|
22
35
|
@callback.call(event)
|
23
36
|
end
|
24
37
|
|
data/lib/slappy/schedule.rb
CHANGED
@@ -2,6 +2,8 @@ require 'securerandom'
|
|
2
2
|
|
3
3
|
module Slappy
|
4
4
|
class Schedule
|
5
|
+
include Slappy::Debuggable
|
6
|
+
|
5
7
|
class OverScheduleError < StandardError; end
|
6
8
|
class InvalidFormatError < StandardError; end
|
7
9
|
|
@@ -9,8 +11,15 @@ module Slappy
|
|
9
11
|
|
10
12
|
def register(schedule, options = {}, &block)
|
11
13
|
id = options[:id] || generate_id
|
12
|
-
|
13
|
-
|
14
|
+
list[id] = Thread.new do
|
15
|
+
time = Chrono::Iterator.new(schedule).next
|
16
|
+
Debug.log "Schedule #{id} registerd to #{schedule}, first call to #{time}"
|
17
|
+
Chrono::Trigger.new(schedule) do
|
18
|
+
block.call
|
19
|
+
time = Chrono::Iterator.new(schedule).next
|
20
|
+
Debug.log "Schedule #{id} called by #{schedule}, next call to #{time}"
|
21
|
+
end.run
|
22
|
+
end
|
14
23
|
id
|
15
24
|
end
|
16
25
|
|
@@ -19,20 +28,21 @@ module Slappy
|
|
19
28
|
if registered
|
20
29
|
@schedule_list[id].kill
|
21
30
|
@schedule_list.delete id
|
31
|
+
Debug.log "Schedule #{id} deleted"
|
22
32
|
end
|
23
33
|
registered
|
24
34
|
end
|
25
35
|
|
26
|
-
|
27
|
-
|
28
|
-
def schedule_list
|
36
|
+
def list
|
29
37
|
@schedule_list ||= {}
|
30
38
|
end
|
31
39
|
|
40
|
+
private
|
41
|
+
|
32
42
|
def generate_id
|
33
|
-
|
34
|
-
id = format("%0#{
|
35
|
-
id = generate_id if
|
43
|
+
digit = Math.log10(DEFAULT_MAX_THREAD).to_i + 1
|
44
|
+
id = format("%0#{digit}d", SecureRandom.random_number(DEFAULT_MAX_THREAD))
|
45
|
+
id = generate_id if list.include? id
|
36
46
|
id
|
37
47
|
end
|
38
48
|
end
|
data/lib/slappy/version.rb
CHANGED
data/lib/slappy.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'active_support'
|
2
|
-
require 'active_support/core_ext'
|
3
|
-
require 'active_support/concern'
|
4
2
|
require 'chrono'
|
5
3
|
require 'forwardable'
|
6
4
|
require 'hashie'
|
@@ -34,6 +32,7 @@ module Slappy
|
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
35
|
+
require 'slappy/concerns/debuggable'
|
37
36
|
require 'slappy/slack_api/concerns/findable'
|
38
37
|
require 'slappy/slack_api/base'
|
39
38
|
require 'slappy/slack_api/channel'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slappy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wakaba260
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-api
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- lib/slappy/client.rb
|
246
246
|
- lib/slappy/commands/generator.rb
|
247
247
|
- lib/slappy/commands/run.rb
|
248
|
+
- lib/slappy/concerns/debuggable.rb
|
248
249
|
- lib/slappy/configuration.rb
|
249
250
|
- lib/slappy/configuration/robot.rb
|
250
251
|
- lib/slappy/dsl.rb
|