ruboty-slack_rtm 2.2.0 → 2.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
  SHA1:
3
- metadata.gz: 8bd0c0364ece9e2ebd2f1ce6a41a4311f73123fd
4
- data.tar.gz: 4de299278c057094dd8cf13cbffe76ca13ced802
3
+ metadata.gz: b8b132d94e6b54aadda6cfe398f55e4431b165f5
4
+ data.tar.gz: 224dd734bc0e1bffdae46932d819c97ac74ef8e6
5
5
  SHA512:
6
- metadata.gz: 3c24921dd9b60bd12ff632f9ff5f43149fe10e65623b9569df3c9edfd10ea091d698094d3355d869ae99243b78f2961d7006a5a2bda2c424942edde88c0cd54b
7
- data.tar.gz: 0a2d3cc76986ed21306b069b8fb10cfd846f2c18922b228279f92b8bf5c733e5e8e5490dd04c33b86a105d3c48b980cb80988fca8490b24377672bbd9ad4920e
6
+ metadata.gz: e34dcdc874d34b809eae3aedf9c95a3faa8892f69ccf6cb31658caedf95500f9ecee5ba87ff91be2dcb364eeceba067818f254bfd85d63cb758265545969ce37
7
+ data.tar.gz: 163740287c666ca50ac2b96237c5b7bed57a51a1b395d80f71a9756c54f5c9f0977e7ce6eeb17643918d0e1e0122d8029070a8919dbbf0bfb8a76ddee1074591
@@ -8,6 +8,7 @@ module Ruboty
8
8
  class SlackRTM < Base
9
9
  env :SLACK_TOKEN, "Account's token. get one on https://api.slack.com/web#basics"
10
10
  env :SLACK_EXPOSE_CHANNEL_NAME, "if this set to 1, message.to will be channel name instead of id", optional: true
11
+ env :SLACK_IGNORE_BOT_MESSAGE, "If this set to 1, bot ignores bot_messages", optional: true
11
12
  env :SLACK_IGNORE_GENERAL, "if this set to 1, bot ignores all messages on #general channel", optional: true
12
13
  env :SLACK_GENERAL_NAME, "Set general channel name if your Slack changes general name", optional: true
13
14
 
@@ -25,7 +26,7 @@ module Ruboty
25
26
 
26
27
  return unless channel
27
28
 
28
- realtime.send(
29
+ realtime.send_message(
29
30
  type: 'message',
30
31
  channel: channel,
31
32
  text: message[:code] ? "```\n#{message[:body]}\n```" : resolve_send_mention(message[:body]),
@@ -49,7 +50,7 @@ module Ruboty
49
50
  end
50
51
 
51
52
  def bind
52
- realtime.on(:message) do |data|
53
+ realtime.on_text do |data|
53
54
  method_name = "on_#{data['type']}".to_sym
54
55
  send(method_name, data) if respond_to?(method_name, true)
55
56
  end
@@ -103,6 +104,10 @@ module Ruboty
103
104
 
104
105
  channel = channel_info(data['channel'])
105
106
 
107
+ if data['type'] == 'bot_message' && ENV['SLACK_IGNORE_BOT_MESSAGE'] == '1'
108
+ return
109
+ end
110
+
106
111
  if channel
107
112
  return if channel['name'] == (ENV['SLACK_GENERAL_NAME'] || 'general') && ENV['SLACK_IGNORE_GENERAL'] == '1'
108
113
 
@@ -123,6 +128,8 @@ module Ruboty
123
128
  )
124
129
  end
125
130
 
131
+ alias on_bot_message on_message
132
+
126
133
  def on_channel_change(data)
127
134
  make_channels_cache
128
135
  end
@@ -289,7 +296,7 @@ module Ruboty
289
296
 
290
297
  def resolve_channel_id(name)
291
298
  ret_id = nil
292
- @channel_info_cahces.each_pair do |id, channel|
299
+ @channel_info_caches.each_pair do |id, channel|
293
300
  if channel['name'] == name
294
301
  ret_id = id
295
302
  break
@@ -10,14 +10,24 @@ module Ruboty
10
10
  @queue = Queue.new
11
11
  end
12
12
 
13
- def send(data)
13
+ def send_message(data)
14
14
  data[:id] = Time.now.to_i * 10 + rand(10)
15
15
  @queue.enq(data.to_json)
16
16
  end
17
17
 
18
- def on(event, &block)
19
- @client.on(event) do |message|
20
- block.call(JSON.parse(message.data))
18
+ def on_text(&block)
19
+ @client.on(:message) do |message|
20
+ case message.type
21
+ when :ping
22
+ Ruboty.logger.debug("#{Client.name}: Received ping message")
23
+ send('', type: 'pong')
24
+ when :pong
25
+ Ruboty.logger.debug("#{Client.name}: Received pong message")
26
+ when :text
27
+ block.call(JSON.parse(message.data))
28
+ else
29
+ Ruboty.logger.warn("#{Client.name}: Received unknown message type=#{message.type}: #{message.data}")
30
+ end
21
31
  end
22
32
  end
23
33
 
@@ -33,7 +43,7 @@ module Ruboty
33
43
  private
34
44
 
35
45
  def create_client(url)
36
- WebSocket::Client::Simple.connect(url).tap do |client|
46
+ WebSocket::Client::Simple.connect(url, verify_mode: OpenSSL::SSL::VERIFY_PEER).tap do |client|
37
47
  client.on(:error) do |err|
38
48
  Ruboty.logger.error("#{err.class}: #{err.message}\n#{err.backtrace.join("\n")}")
39
49
  end
@@ -44,7 +54,7 @@ module Ruboty
44
54
  Thread.start do
45
55
  loop do
46
56
  sleep(30)
47
- @client.send(type: 'ping')
57
+ @client.send('', type: 'ping')
48
58
  end
49
59
  end
50
60
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module SlackRTM
3
- VERSION = '2.2.0'
3
+ VERSION = '2.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-slack_rtm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Kusano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-22 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.6.3
135
+ rubygems_version: 2.5.1
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Slack real time messaging adapter for Ruboty