mobb 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +49 -3
- data/lib/mobb/base.rb +58 -9
- data/lib/mobb/version.rb +1 -1
- data/mobb.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45908e7b9ee455eade38bebbe8aa457b93df93013aec972e3fecc16b0d982dfc
|
4
|
+
data.tar.gz: c3b6343d33c5277093970e3100bdcc68a3573195380e3e4b286806472c2ef009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 635f87290e06901ecbac6444c15f89aa0e48753e518ceecae6a12aa34c0e305f939fe3ec2eec7db6f9c18088a51e8957423c5ad7a2688b7f7454480922d8e55b
|
7
|
+
data.tar.gz: 75682d95b5903622e0ca0b6b0b0a2828331f1d67ffa2f5cf4e4e4acb6848c5873b70bcb53c431c3ebcad048bed35d804ef5313d0cae6de69af51368771a8ec09
|
data/README.md
CHANGED
@@ -71,17 +71,19 @@ end
|
|
71
71
|
|
72
72
|
## Conditions
|
73
73
|
|
74
|
-
You can use conditions `
|
74
|
+
You can use conditions `react_to_bot`, `include_myself` and `reply_to_me`.
|
75
75
|
|
76
76
|
```ruby
|
77
77
|
require 'mobb'
|
78
78
|
set :service, 'slack'
|
79
79
|
|
80
|
-
#
|
81
|
-
|
80
|
+
# Mobb ignore all bot messages, but when set reply_to_bot true, Mobb react all bot messages
|
81
|
+
# this example will act infinit loop when receive message 'Yo'
|
82
|
+
on 'Yo', reply_to_bot: true do
|
82
83
|
'Yo'
|
83
84
|
end
|
84
85
|
|
86
|
+
# This block react only message reply to bot
|
85
87
|
on /Hi/, reply_to_me: true do
|
86
88
|
"Hi #{@env.user.name}"
|
87
89
|
end
|
@@ -104,6 +106,50 @@ on /Yo/, reply_to_me: true do
|
|
104
106
|
end
|
105
107
|
```
|
106
108
|
|
109
|
+
# Chain methods
|
110
|
+
|
111
|
+
If you want to act heavy task your bot, you can use chain/trigger syntax.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
require 'mobb'
|
115
|
+
|
116
|
+
on 'taks start (\w+)' do |name|
|
117
|
+
chain 'heavy task1', 'heavy task2', name: name
|
118
|
+
'start!'
|
119
|
+
end
|
120
|
+
|
121
|
+
trigger 'heavy task1' do
|
122
|
+
payload = @env.payload
|
123
|
+
sleep 19
|
124
|
+
"task1 #{payload[:name]} done!"
|
125
|
+
end
|
126
|
+
|
127
|
+
trigger 'heavy task1' do
|
128
|
+
payload = @env.payload
|
129
|
+
sleep 30
|
130
|
+
"task2 #{payload[:name]} done!"
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
# Pass
|
135
|
+
|
136
|
+
You can pass block to use pass keyword
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
require 'mobb'
|
140
|
+
|
141
|
+
on 'yo' do
|
142
|
+
$stderr.puts 'this block will be pass'
|
143
|
+
pass
|
144
|
+
'this value never evaluted'
|
145
|
+
end
|
146
|
+
|
147
|
+
on 'yo' do
|
148
|
+
$stderr.puts 'catch!'
|
149
|
+
'yo'
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
107
153
|
# Service handlers
|
108
154
|
|
109
155
|
Mobb is implemented based on [Repp](https://github.com/kinoppyd/repp) Interface.
|
data/lib/mobb/base.rb
CHANGED
@@ -27,8 +27,8 @@ module Mobb
|
|
27
27
|
end
|
28
28
|
|
29
29
|
class Matched
|
30
|
-
attr_reader :pattern, :matched
|
31
|
-
def initialize(pattern, matched) @pattern, @matched = pattern, matched; end
|
30
|
+
attr_reader :pattern, :matched, :captures
|
31
|
+
def initialize(pattern, matched) @pattern, @matched, @captures = pattern, matched, matched.captures; end
|
32
32
|
end
|
33
33
|
|
34
34
|
def pattern; @pattern; end
|
@@ -37,7 +37,7 @@ module Mobb
|
|
37
37
|
case pattern
|
38
38
|
when Regexp
|
39
39
|
if res = pattern.match(string)
|
40
|
-
Matched.new(pattern, res
|
40
|
+
Matched.new(pattern, res)
|
41
41
|
else
|
42
42
|
false
|
43
43
|
end
|
@@ -57,14 +57,23 @@ module Mobb
|
|
57
57
|
end
|
58
58
|
|
59
59
|
class Base
|
60
|
+
attr_reader :matched
|
61
|
+
|
60
62
|
def call(env)
|
61
63
|
dup.call!(env)
|
62
64
|
end
|
63
65
|
|
64
66
|
def call!(env)
|
65
67
|
@env = env
|
68
|
+
@body = nil
|
69
|
+
@repp_options = {}
|
70
|
+
@attachments = {}
|
71
|
+
@matched = nil
|
72
|
+
@silent = false
|
66
73
|
invoke { dispatch! }
|
67
|
-
|
74
|
+
|
75
|
+
@body = nil if @silent
|
76
|
+
[@body, @repp_options, @attachments]
|
68
77
|
end
|
69
78
|
|
70
79
|
def dispatch!
|
@@ -131,7 +140,8 @@ module Mobb
|
|
131
140
|
|
132
141
|
case res
|
133
142
|
when ::Mobb::Matcher::Matched
|
134
|
-
|
143
|
+
@matched = res.matched
|
144
|
+
block ? block[self, *(res.captures)] : yield(self, *(res.captures))
|
135
145
|
when TrueClass
|
136
146
|
block ? block[self] : yield(self)
|
137
147
|
else
|
@@ -142,6 +152,17 @@ module Mobb
|
|
142
152
|
|
143
153
|
def event_eval; throw :halt, yield; end
|
144
154
|
|
155
|
+
def chain(*args)
|
156
|
+
payload = args.last.instance_of?(Hash) ? args.pop : nil
|
157
|
+
@repp_options[:trigger] = { names: args, payload: payload }
|
158
|
+
end
|
159
|
+
|
160
|
+
def say_nothing; @silent = true; end
|
161
|
+
|
162
|
+
def pass(&block)
|
163
|
+
throw :pass, block
|
164
|
+
end
|
165
|
+
|
145
166
|
def settings
|
146
167
|
self.class.settings
|
147
168
|
end
|
@@ -157,6 +178,13 @@ module Mobb
|
|
157
178
|
/src\/kernel\/bootstrap\/[A-Z]/ # maglev kernel files
|
158
179
|
]
|
159
180
|
|
181
|
+
DEFAULT_CONDITIONS = {
|
182
|
+
:message => {
|
183
|
+
:react_to_bot => false,
|
184
|
+
:include_myself => false
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
160
188
|
attr_reader :events, :filters
|
161
189
|
|
162
190
|
def reset!
|
@@ -197,6 +225,8 @@ module Mobb
|
|
197
225
|
def cron(pattern, options = {}, &block) event(:ticker, pattern, options, &block); end
|
198
226
|
alias :every :cron
|
199
227
|
|
228
|
+
def trigger(name, options = {}, &block) event(:trigger, name, options, &block); end
|
229
|
+
|
200
230
|
def event(type, pattern, options, &block)
|
201
231
|
signature = compile!(type, pattern, options, &block)
|
202
232
|
(@events[type] ||= []) << signature
|
@@ -210,6 +240,9 @@ module Mobb
|
|
210
240
|
|
211
241
|
def compile!(type, pattern, options, &block)
|
212
242
|
at = options.delete(:at)
|
243
|
+
|
244
|
+
defaults = DEFAULT_CONDITIONS[type]
|
245
|
+
options = defaults ? defaults.merge(options) : options
|
213
246
|
options.each_pair { |option, args| send(option, *args) }
|
214
247
|
|
215
248
|
matcher = case type
|
@@ -217,6 +250,8 @@ module Mobb
|
|
217
250
|
compile(pattern, options)
|
218
251
|
when :ticker
|
219
252
|
compile_cron(pattern, at)
|
253
|
+
when :trigger
|
254
|
+
compile(pattern, options)
|
220
255
|
else
|
221
256
|
compile(pattern, options)
|
222
257
|
end
|
@@ -316,9 +351,17 @@ module Mobb
|
|
316
351
|
end
|
317
352
|
end
|
318
353
|
|
319
|
-
def
|
320
|
-
|
321
|
-
|
354
|
+
def react_to_bot(cond)
|
355
|
+
source_condition do
|
356
|
+
return true if !@env.respond_to?(:bot?) || cond
|
357
|
+
!@env.bot?
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
def include_myself(cond)
|
362
|
+
source_condition do
|
363
|
+
return true if !@env.respond_to?(:user) || cond
|
364
|
+
@env.user.name != settings.name
|
322
365
|
end
|
323
366
|
end
|
324
367
|
|
@@ -328,6 +371,12 @@ module Mobb
|
|
328
371
|
end
|
329
372
|
end
|
330
373
|
|
374
|
+
def silent(cond)
|
375
|
+
dest_condition do |res|
|
376
|
+
res[0] = nil if cond
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
331
380
|
def dest_to(channel)
|
332
381
|
dest_condition do |res|
|
333
382
|
res.last[:dest_channel] = channel
|
@@ -467,7 +516,7 @@ module Mobb
|
|
467
516
|
end
|
468
517
|
end
|
469
518
|
|
470
|
-
delegate :receive, :on, :every, :cron,
|
519
|
+
delegate :receive, :on, :every, :cron, :trigger,
|
471
520
|
:set, :enable, :disable, :clear, :before, :after,
|
472
521
|
:helpers, :register
|
473
522
|
|
data/lib/mobb/version.rb
CHANGED
data/mobb.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kinoppyd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
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: repp
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: whenever
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|