slappy 0.6.0 → 0.6.1

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
  SHA1:
3
- metadata.gz: f8af98612f787abf18da9970dae3c2774eb02617
4
- data.tar.gz: b293a5cba0cc0c58fab718447b2d1646f1a73fa5
3
+ metadata.gz: 08b2f8a7bb472cacd6e51da0269ee094156f5c3a
4
+ data.tar.gz: d48fb38cd54741eb27c1fbf5da175b83b6d43066
5
5
  SHA512:
6
- metadata.gz: 0838f8be93626934b4b8d8c0322ad19db775140536ae31764b0ba7f72e70938d2e26bf68130e488bed397beb4135e1249d8d32893bf16205bc9a0eeb4143f528
7
- data.tar.gz: b95e4c625e0a4f32d35844885cfafd3533538396e64c7439169e3ce025d156d70f937019b89260529b835b99a5c4f2506ebddab22e456d13dbcd8f39bcb30337
6
+ metadata.gz: 718627aa86b2ea59910af1088b9625b4059e6b98d21cca3a685bb469ae1e9c2666e0878d0f566881bcf9c0a6c335e12cb26afea5e93bff0887b1ba6c21c52706
7
+ data.tar.gz: 02c6b3286816b055d29a596d01a5a8a22c41ceed109f0a09f82c836e3aa9fb5cf1ff08fd67c26cdb0ac9490195041e109c825b7c5b4fce856fe5b2c0f4dff439
data/README.md CHANGED
@@ -106,6 +106,7 @@ Slappy.say 'hello!' #=> username: slappy, channel: '#general', icon_emoji: ':sla
106
106
  ```
107
107
  token - default: ENV['SLACK_TOKEN']
108
108
  scripts_dir_path - default : 'slappy-scripts'
109
+ stop_with_error - default: true
109
110
 
110
111
  robot.botname - not effect now
111
112
  robot.username - default: 'slappy'
@@ -178,12 +179,34 @@ There conditions, this event be called:
178
179
  - `raise StandardError` in script
179
180
  - trap SIGTERM or SIGINT
180
181
 
181
- ```
182
+ ```ruby
182
183
  goodnight do
183
184
  logger.info 'goodnight'
184
185
  end
185
186
  ```
186
187
 
188
+ #### From Option
189
+
190
+ From Option enable to `hear`, `monitor`, and `respond`.
191
+ This option specify reaction target!
192
+
193
+ ```ruby
194
+ # specify target channel
195
+ hear 'slappy', from: { channel: '#slappy' } do |event|
196
+ logger.info 'slappy!'
197
+ end
198
+
199
+ # specify target user
200
+ hear 'slappy', from: { username: '@slappy' } do |event|
201
+ logger.info 'slappy!'
202
+ end
203
+
204
+ # specify target user and channel
205
+ hear 'slappy', from: { channel: '#slappy', username: '@slappy' } do |event|
206
+ logger.info 'slappy!'
207
+ end
208
+ ```
209
+
187
210
  ### DSL Methods
188
211
 
189
212
  |method|when execute callback|
@@ -197,7 +220,7 @@ end
197
220
 
198
221
  ### Event Methods
199
222
 
200
- ```
223
+ ```ruby
201
224
  hear 'slappy' do |event|
202
225
  return if event.bot_message? #=> check message from webhook or integration
203
226
  event.relpy 'slappy' #=> relpy to event channel
@@ -207,6 +230,7 @@ end
207
230
 
208
231
  |method|description|
209
232
  |:---:|:---|
233
+ |data|get response JSON Hash (Hashie::Mash) from Slack API|
210
234
  |bot_message?|check message from bot (webhook or integration is true)|
211
235
  |reply|reply message to event channel|
212
236
  |reaction|add reaction to event message|
@@ -216,7 +240,7 @@ end
216
240
 
217
241
  If you not want execute `slappy start` command, written by (require `'slappy/dsl'` use DSL):
218
242
 
219
- ```
243
+ ```ruby
220
244
  require 'slappy'
221
245
 
222
246
  Slappy.hello do
@@ -230,7 +254,16 @@ Slappy.start #=> Start WebSocket connection
230
254
 
231
255
  ## Release Note
232
256
 
257
+ - v0.6.1
258
+ - Fix ts validation
259
+ - validation skil when ts be nil
260
+ - Fix option be bang change in Messenger#initialize
261
+ - Add Event#data
262
+ - Add stop_with_error option
263
+
233
264
  - v0.6.0
265
+ - Add from option to hear, monitor
266
+ - specify event target
234
267
  - respond method
235
268
  - respond event call when add message to botname prefix
236
269
  - goodnight method
data/lib/slappy/client.rb CHANGED
@@ -14,19 +14,17 @@ module Slappy
14
14
  end
15
15
 
16
16
  def start
17
- @start_time = Time.now
18
- @callbacks.each do |event_name, listeners|
19
- register_event event_name, listeners
20
- end
21
- set_signal_trap
17
+ setup
18
+
22
19
  Debug.log 'Slappy start'
20
+
23
21
  begin
24
22
  client.start
25
23
  rescue StandardError => e
26
24
  @callbacks[:goodnight].each(&:call) if @callbacks[:goodnight]
27
25
  STDERR.puts e.backtrace.slice!(0) + ': ' + e.message
28
26
  STDERR.puts "\tfrom " + e.backtrace.join("\n\tfrom ")
29
- exit 1
27
+ exit 1 if config.stop_with_error
30
28
  end
31
29
  end
32
30
 
@@ -66,6 +64,16 @@ module Slappy
66
64
 
67
65
  private
68
66
 
67
+ def setup
68
+ @start_time = Time.now
69
+
70
+ @callbacks.each do |event_name, listeners|
71
+ register_event event_name, listeners
72
+ end
73
+
74
+ set_signal_trap
75
+ end
76
+
69
77
  def register_callback(name, type, callback)
70
78
  @callbacks[type] ||= []
71
79
  @callbacks[type].push callback
@@ -1,11 +1,16 @@
1
1
  module Slappy
2
2
  class Configuration
3
- attr_accessor :robot, :token, :scripts_dir_path, :lib_dir_path, :logger
3
+ attr_accessor :robot, :token, :scripts_dir_path, :lib_dir_path, :logger, :stop_with_error
4
4
 
5
5
  def initialize
6
6
  @robot = Robot.new
7
7
  end
8
8
 
9
+ def stop_with_error
10
+ @stop_with_error = true if @stop_with_error.nil?
11
+ @stop_with_error
12
+ end
13
+
9
14
  def logger
10
15
  unless @logger
11
16
  @logger = Logger.new(STDOUT)
@@ -15,7 +20,7 @@ module Slappy
15
20
  end
16
21
 
17
22
  def token
18
- @token || ENV['SLACK_TOKEN']
23
+ @token ||= ENV['SLACK_TOKEN']
19
24
  end
20
25
 
21
26
  def config_file_path
@@ -23,15 +28,15 @@ module Slappy
23
28
  end
24
29
 
25
30
  def lib_dir_path
26
- @lib_dir_path || './lib'
31
+ @lib_dir_path ||= './lib'
27
32
  end
28
33
 
29
34
  def scripts_dir_path
30
- @scripts_dir_path || './slappy-scripts'
35
+ @scripts_dir_path ||= './slappy-scripts'
31
36
  end
32
37
 
33
38
  def dsl
34
- @dsl || :enabled
39
+ @dsl ||= :enabled
35
40
  end
36
41
 
37
42
  def dsl=(symbol)
data/lib/slappy/event.rb CHANGED
@@ -3,7 +3,7 @@ module Slappy
3
3
  extend Forwardable
4
4
  include Debuggable
5
5
 
6
- attr_accessor :matches
6
+ attr_accessor :matches, :data
7
7
 
8
8
  def_delegators :@data, :method_missing, :respond_to_missing?
9
9
 
@@ -29,6 +29,7 @@ module Slappy
29
29
  private
30
30
 
31
31
  def time_valid?(event)
32
+ return true if event.ts.nil?
32
33
  event.ts > Slappy.client.start_time
33
34
  end
34
35
  end
@@ -4,11 +4,12 @@ module Slappy
4
4
 
5
5
  CHANNEL_APIS = [SlackAPI::Channel, SlackAPI::Group, SlackAPI::Direct]
6
6
 
7
- def initialize(options)
7
+ def initialize(options = {})
8
+ opt = options.dup
8
9
  @destination = {}
9
- @destination = options[:channel]
10
- options.delete :channel
11
- @options = options
10
+ @destination = opt[:channel]
11
+ opt.delete :channel
12
+ @options = opt
12
13
  end
13
14
 
14
15
  def message
@@ -38,18 +38,7 @@ module Slappy
38
38
 
39
39
  def list(options = {})
40
40
  register_monitor
41
-
42
- unless @list
43
- method_name = "#{api_name}_list"
44
-
45
- options[:channel] = SlackAPI.find(options[:channel]).id if options[:channel]
46
- result = Slack.send(method_name, options)
47
- unless result['ok']
48
- exception = SlackError.new "Error message from slack (#{result['error']})"
49
- fail exception, exception.message
50
- end
51
- @list = result[list_name].map { |data| new(data) }
52
- end
41
+ @list = get_list(options) unless @list
53
42
  @list
54
43
  end
55
44
 
@@ -69,6 +58,22 @@ module Slappy
69
58
  def find_by_keyword(hash)
70
59
  hash.map { |key, value| list.find { |obj| obj.send(key) == value } }.first
71
60
  end
61
+
62
+ private
63
+
64
+ def get_list(options = {})
65
+ method_name = "#{api_name}_list"
66
+
67
+ options[:channel] = SlackAPI.find(options[:channel]).id if options[:channel]
68
+ result = Slack.send(method_name, options)
69
+
70
+ unless result['ok']
71
+ exception = SlackError.new "Error message from slack (#{result['error']})"
72
+ fail exception, exception.message
73
+ end
74
+
75
+ result[list_name].map { |data| new(data) }
76
+ end
72
77
  end
73
78
  end
74
79
  end
@@ -1,3 +1,3 @@
1
1
  module Slappy
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -29,6 +29,12 @@ Slappy.configure do |config|
29
29
  #
30
30
  # config.dsl = :enabled
31
31
 
32
+ # stop_with_error:
33
+ # Select bot be stop when catch StandardError.
34
+ # If false, puts stack trace but be not stop when bot catch StandardError.
35
+ #
36
+ # config.stop_with_exception = true
37
+
32
38
  ## Default parameters
33
39
  #
34
40
  # There parameters use in say method when send to Slack.
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.6.0
4
+ version: 0.6.1
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-22 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-api
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  version: '0'
293
293
  requirements: []
294
294
  rubyforge_project:
295
- rubygems_version: 2.4.5.1
295
+ rubygems_version: 2.5.0
296
296
  signing_key:
297
297
  specification_version: 4
298
298
  summary: Simple Slack Bot Framework