slack-bot-server 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cc965f9cb1a969b0ea3f1b58f467084aa308552
4
- data.tar.gz: b409898adb366f5420d6403f83015b0c05a366d1
3
+ metadata.gz: 504c4decb4b2eacb0315295a18eced229b625964
4
+ data.tar.gz: 212c468b3d11018a48c966a1db9b4152f61b4f49
5
5
  SHA512:
6
- metadata.gz: e0488b12f7bb24e7310e974e07f24d0775bc4d977783066c94bd0460c27e36d56540807cbd498362d6b163cff19aff16266388dacd8f43123b056031288cba89
7
- data.tar.gz: c6a89f534877ea4ca3433ad8ee2e732f2fc4c848750f90a6e7a129a98d4d0e724e2d0af7b027ba5b8b44f452d0f1514246d68e58bb3463acf7ab875a0bb3b55f
6
+ metadata.gz: f93f32bd83af717a663f5e995eea4678f24c5b2db744dbec043e40e5b7a79e52823130cbd22bad4821e87c89c429cd5322d06bccd12d04087ed9f410a6d313a2
7
+ data.tar.gz: a277171fd3fa7b384118992cf1b2d80777ab3ea05bbcbd2156f241c64d1063321190364b263d9e7497944aa991f88420cbfb01a5c6b6cc1328fbe8fae49b58c0
@@ -1,5 +1,13 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.4.3
4
+
5
+ ### Changes
6
+ - Add `clear` method to queues
7
+ - Upgrate `slack-ruby-client` dependency to latest version
8
+
9
+ ## 0.4.2
10
+
3
11
  ### Changes
4
12
  - Re-use error raising from within Slack::Web::Api
5
13
  - Prevent bots with the same key as existing bots from being added (@keydunov)
data/README.md CHANGED
@@ -132,9 +132,9 @@ class SlackBotServer::SimpleBot < SlackBotServer::Bot
132
132
  # only 'how are you'.
133
133
  on_mention do |data|
134
134
  if data['message'] == 'who are you'
135
- reply text: "I am #{user} (user id: #{user_id}, connected to team #{team} with team id #{team_id}"
135
+ reply text: "I am #{bot_user_name} (user id: #{bot_user_id}, connected to team #{team_name} with team id #{team_id}"
136
136
  else
137
- reply text: "You said '#{data['message']}', and I'm frankly fascinated."
137
+ reply text: "You said '#{data.message}', and I'm frankly fascinated."
138
138
  end
139
139
  end
140
140
 
@@ -18,7 +18,7 @@ require 'slack-ruby-client'
18
18
  # # only 'how are you'.
19
19
  # on_mention do |data|
20
20
  # if data['message'] == 'who are you'
21
- # reply text: "I am #{user} (user id: #{user_id}, connected to team #{team} with team id #{team_id}"
21
+ # reply text: "I am #{bot_user_name} (user id: #{bot_user_id}, connected to team #{team_name} with team id #{team_id}"
22
22
  # else
23
23
  # reply text: "You said '#{data['message']}', and I'm frankly fascinated."
24
24
  # end
@@ -51,8 +51,6 @@ class SlackBotServer::Bot
51
51
  def initialize(token:, key: nil)
52
52
  @token = token
53
53
  @key = key || @token
54
- @im_channels = []
55
- @channels = []
56
54
  @connected = false
57
55
  @running = false
58
56
  end
@@ -60,22 +58,22 @@ class SlackBotServer::Bot
60
58
  # Returns the username (for @ replying) of the bot user we are connected as,
61
59
  # e.g. +'simple_bot'+
62
60
  def bot_user_name
63
- @client.self['name']
61
+ @client.self.name
64
62
  end
65
63
 
66
64
  # Returns the ID of the bot user we are connected as, e.g. +'U123456'+
67
65
  def bot_user_id
68
- @client.self['id']
66
+ @client.self.id
69
67
  end
70
68
 
71
69
  # Returns the name of the team we are connected to, e.g. +'My Team'+
72
70
  def team_name
73
- @client.team['name']
71
+ @client.team.name
74
72
  end
75
73
 
76
74
  # Returns the ID of the team we are connected to, e.g. +'T234567'+
77
75
  def team_id
78
- @client.team['id']
76
+ @client.team.id
79
77
  end
80
78
 
81
79
  # Send a message to Slack
@@ -103,8 +101,8 @@ class SlackBotServer::Bot
103
101
  # @param options [Hash] As {#say}, although the +:channel+ option is
104
102
  # redundant
105
103
  def broadcast(options)
106
- @channels.each do |channel|
107
- say(options.merge(channel: channel['id']))
104
+ @client.channels.each do |id, _|
105
+ say(options.merge(channel: id))
108
106
  end
109
107
  end
110
108
 
@@ -113,7 +111,7 @@ class SlackBotServer::Bot
113
111
  # @param options [Hash] As {#say}, although the +:channel+ option is
114
112
  # redundant
115
113
  def reply(options)
116
- channel = @last_received_data['channel']
114
+ channel = @last_received_data.channel
117
115
  say(options.merge(channel: channel))
118
116
  end
119
117
 
@@ -123,7 +121,7 @@ class SlackBotServer::Bot
123
121
  # redundant
124
122
  def say_to(user_id, options)
125
123
  result = @client.web_client.im_open(user: user_id)
126
- channel = result['channel']['id']
124
+ channel = result.channel.id
127
125
  say(options.merge(channel: channel))
128
126
  end
129
127
 
@@ -131,7 +129,7 @@ class SlackBotServer::Bot
131
129
  # @param options [Hash] can contain +:channel+, which should be an ID; if no options
132
130
  # are provided, the channel from the most recently recieved message is used
133
131
  def typing(options={})
134
- last_received_channel = @last_received_data ? @last_received_data['channel'] : nil
132
+ last_received_channel = @last_received_data ? @last_received_data.channel : nil
135
133
  default_options = {channel: last_received_channel}
136
134
  @client.typing(default_options.merge(options))
137
135
  end
@@ -167,22 +165,6 @@ class SlackBotServer::Bot
167
165
  end
168
166
  end
169
167
 
170
- @client.on :im_created do |data|
171
- log "Adding new IM channel", data['channel']
172
- @im_channels << data['channel']
173
- end
174
-
175
- @client.on :channel_joined do |data|
176
- log "Adding new channel", data['channel']
177
- @channels << data['channel']
178
- end
179
-
180
- @client.on :channel_left do |data|
181
- channel_id = data['channel']
182
- log "Removing channel: #{channel_id}"
183
- @channels.delete_if { |c| c['id'] == channel_id }
184
- end
185
-
186
168
  @client.on :close do |event|
187
169
  log "disconnected"
188
170
  @connected = false
@@ -326,10 +308,10 @@ class SlackBotServer::Bot
326
308
  on(:message) do |data|
327
309
  debug on_message: data, bot_message: bot_message?(data)
328
310
  if !bot_message?(data) &&
329
- (data['text'] =~ /\A(#{mention_keywords.join('|')})[\s\:](.*)/i ||
330
- data['text'] =~ /\A(<@#{bot_user_id}>)[\s\:](.*)/)
311
+ (data.text =~ /\A(#{mention_keywords.join('|')})[\s\:](.*)/i ||
312
+ data.text =~ /\A(<@#{bot_user_id}>)[\s\:](.*)/)
331
313
  message = $2.strip
332
- @last_received_data = data.merge('message' => message)
314
+ @last_received_data = data.merge(message: message)
333
315
  instance_exec(@last_received_data, &block)
334
316
  end
335
317
  end
@@ -339,18 +321,18 @@ class SlackBotServer::Bot
339
321
  # to this bot
340
322
  def on_im(&block)
341
323
  on(:message) do |data|
342
- debug on_im: data, bot_message: bot_message?(data), is_im_channel: is_im_channel?(data['channel'])
343
- if is_im_channel?(data['channel']) && !bot_message?(data)
344
- @last_received_data = data.merge('message' => data['text'])
324
+ debug on_im: data, bot_message: bot_message?(data), is_im_channel: is_im_channel?(data.channel)
325
+ if is_im_channel?(data.channel) && !bot_message?(data)
326
+ @last_received_data = data.merge(message: data.text)
345
327
  instance_exec(@last_received_data, &block)
346
328
  end
347
329
  end
348
330
  end
349
331
  end
350
332
 
351
- on :start do
352
- load_channels
353
- end
333
+ # on :start do
334
+ # load_channels
335
+ # end
354
336
 
355
337
  on :finish do
356
338
  start if @running
@@ -365,7 +347,7 @@ class SlackBotServer::Bot
365
347
  private
366
348
 
367
349
  def handle_message(data)
368
- run_callbacks(data['type'], data)
350
+ run_callbacks(data.type, data)
369
351
  end
370
352
 
371
353
  def run_callbacks(type, data=nil)
@@ -393,32 +375,20 @@ class SlackBotServer::Bot
393
375
  "[BOT/#{bot_user_name}] #{text}"
394
376
  end
395
377
 
396
- def load_channels
397
- debug "Loading channels"
398
- @im_channels = @client.ims
399
- debug im_channels: @im_channels
400
- @channels = @client.channels.select { |d| d['is_member'] == true }
401
- debug channels: @channels
402
- end
403
-
404
- def channel(id)
405
- (@channels + @im_channels).find { |c| c['id'] == id }
406
- end
407
-
408
378
  def is_im_channel?(id)
409
- channel(id)['is_im'] == true
379
+ @client.ims[id] != nil
410
380
  end
411
381
 
412
382
  def bot_message?(data)
413
- data['subtype'] == 'bot_message' ||
414
- data['user'] == SLACKBOT_USER_ID ||
415
- data['user'] == bot_user_id ||
383
+ data.subtype == 'bot_message' ||
384
+ data.user == SLACKBOT_USER_ID ||
385
+ data.user == bot_user_id ||
416
386
  change_to_previous_bot_message?(data)
417
387
  end
418
388
 
419
389
  def change_to_previous_bot_message?(data)
420
- data['subtype'] == 'message_changed' &&
421
- data['previous_message']['user'] == bot_user_id
390
+ data.subtype == 'message_changed' &&
391
+ data.previous_message.user == bot_user_id
422
392
  end
423
393
 
424
394
  def rtm_incompatible_message?(data)
@@ -21,4 +21,10 @@ class SlackBotServer::LocalQueue
21
21
  value = @queue.pop(true) rescue ThreadError
22
22
  value == ThreadError ? nil : value
23
23
  end
24
+
25
+ # Clear the queue
26
+ # @return [nil]
27
+ def clear
28
+ @queue = Queue.new
29
+ end
24
30
  end
@@ -34,4 +34,10 @@ class SlackBotServer::RedisQueue
34
34
  nil
35
35
  end
36
36
  end
37
+
38
+ # Clears the queue
39
+ # @return [nil]
40
+ def clear
41
+ @redis.del @key
42
+ end
37
43
  end
@@ -12,7 +12,7 @@ class SlackBotServer::SimpleBot < SlackBotServer::Bot
12
12
  # only 'how are you'.
13
13
  on_mention do |data|
14
14
  if data['message'] == 'who are you'
15
- reply text: "I am #{user} (id: #{user_id}), connected to team #{team} (id #{team_id})"
15
+ reply text: "I am #{bot_user_name} (user id: #{bot_user_id}), connected to team #{team_name} with team id #{team_id}"
16
16
  else
17
17
  reply text: "You said '#{data['message']}', and I'm frankly fascinated."
18
18
  end
@@ -1,4 +1,4 @@
1
1
  module SlackBotServer
2
2
  # The current version of the +SlackBotServer+ framework
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "slack-ruby-client", "~> 0.5.3"
22
+ spec.add_dependency "slack-ruby-client", "~> 0.7"
23
23
  spec.add_dependency "faye-websocket", "~> 0.10"
24
24
  spec.add_dependency "multi_json"
25
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-bot-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Adam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.3
19
+ version: '0.7'
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.5.3
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faye-websocket
29
29
  requirement: !ruby/object:Gem::Requirement