slack-bot-server 0.4.5 → 0.4.6

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: f1086fe2f192f0ea950041f91799d67bc8e7966e
4
- data.tar.gz: 85e02d179a2fb1ca62c8064206244fb3da90c197
3
+ metadata.gz: d6685270303a7d38f8c8b833048eec1a68c17680
4
+ data.tar.gz: 48e3b42af56269b7f9eba8acb397902a8e780bc8
5
5
  SHA512:
6
- metadata.gz: 6c48425cac63a28ffe08a8af43702183b532127307f61807db94088470e6a4d050011fb5c5b732ba10d00ab8eab51736b73b9c98aa7d2e97fbc6fb5d803e6daa
7
- data.tar.gz: 3a09cc3baa9e35cf4193a7638627e584b7b7413ea85fe06ed2b9470393fb295890255bd66cdb6bde928946c44df03d873c3fc373f7151a0a1210392d1b212b45
6
+ metadata.gz: 3efef59a7ef8be23ac6eece069f26d90f6f287b5049cf8e8d4ef4aee867e03ba2f3d461913a26c6b8d61b5a14c024c64b3f26303b1ae2a30cd5ce2cd17b377bf
7
+ data.tar.gz: edc37497ad3846105145918a74c9d507beb262c2105a7de03fe60f608102cfb76faf0010f01e1ccc8513ac3f6fb1a92f270bb16d856f13da8c782e9751dad58b
@@ -1,5 +1,14 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.4.6
4
+
5
+ ### Added
6
+ - New `client` method for accessing the underlying Slack ruby client; this is useful for getting the channels or users (e.g. `client.channels` or `client.users`).
7
+
8
+ ### Changes
9
+ - Evaluate `on_slack_event` blocks against the bot instance, rather than the class.
10
+
11
+
3
12
  ## 0.4.5
4
13
 
5
14
  ### Added
@@ -61,22 +61,22 @@ class SlackBotServer::Bot
61
61
  # Returns the username (for @ replying) of the bot user we are connected as,
62
62
  # e.g. +'simple_bot'+
63
63
  def bot_user_name
64
- @client.self.name
64
+ client.self.name
65
65
  end
66
66
 
67
67
  # Returns the ID of the bot user we are connected as, e.g. +'U123456'+
68
68
  def bot_user_id
69
- @client.self.id
69
+ client.self.id
70
70
  end
71
71
 
72
72
  # Returns the name of the team we are connected to, e.g. +'My Team'+
73
73
  def team_name
74
- @client.team.name
74
+ client.team.name
75
75
  end
76
76
 
77
77
  # Returns the ID of the team we are connected to, e.g. +'T234567'+
78
78
  def team_id
79
- @client.team.id
79
+ client.team.id
80
80
  end
81
81
 
82
82
  # Send a message to Slack
@@ -93,10 +93,10 @@ class SlackBotServer::Bot
93
93
 
94
94
  if rtm_incompatible_message?(message)
95
95
  debug "Sending via Web API", message
96
- @client.web_client.chat_postMessage(message)
96
+ client.web_client.chat_postMessage(message)
97
97
  else
98
98
  debug "Sending via RTM API", message
99
- @client.message(message)
99
+ client.message(message)
100
100
  end
101
101
  end
102
102
 
@@ -104,7 +104,7 @@ class SlackBotServer::Bot
104
104
  # @param options [Hash] As {#say}, although the +:channel+ option is
105
105
  # redundant
106
106
  def broadcast(options)
107
- @client.channels.each do |id, _|
107
+ client.channels.each do |id, _|
108
108
  say(options.merge(channel: id))
109
109
  end
110
110
  end
@@ -123,7 +123,7 @@ class SlackBotServer::Bot
123
123
  # @param options [Hash] As {#say}, although the +:channel+ option is
124
124
  # redundant
125
125
  def say_to(user_id, options)
126
- result = @client.web_client.im_open(user: user_id)
126
+ result = client.web_client.im_open(user: user_id)
127
127
  channel = result.channel.id
128
128
  say(options.merge(channel: channel))
129
129
  end
@@ -134,14 +134,14 @@ class SlackBotServer::Bot
134
134
  def typing(options={})
135
135
  last_received_channel = @last_received_user_message ? @last_received_user_message.channel : nil
136
136
  default_options = {channel: last_received_channel}
137
- @client.typing(default_options.merge(options))
137
+ client.typing(default_options.merge(options))
138
138
  end
139
139
 
140
140
  # Call a method directly on the Slack web API (via Slack::Web::Client).
141
141
  # Useful for debugging only.
142
142
  def call(method, args)
143
143
  args.symbolize_keys!
144
- @client.web_client.send(method, args)
144
+ client.web_client.send(method, args)
145
145
  end
146
146
 
147
147
  # Starts the bot running.
@@ -152,13 +152,13 @@ class SlackBotServer::Bot
152
152
  @client = ::Slack::RealTime::Client.new(token: @token)
153
153
  @running = true
154
154
 
155
- @client.on :open do |event|
155
+ client.on :open do |event|
156
156
  @connected = true
157
157
  log "connected to '#{team_name}'"
158
158
  run_callbacks(:start)
159
159
  end
160
160
 
161
- @client.on :message do |data|
161
+ client.on :message do |data|
162
162
  begin
163
163
  debug message: data
164
164
  @last_received_user_message = data if user_message?(data)
@@ -168,15 +168,15 @@ class SlackBotServer::Bot
168
168
  end
169
169
  end
170
170
 
171
- @client.on :close do |event|
171
+ client.on :close do |event|
172
172
  log "disconnected"
173
173
  @connected = false
174
174
  run_callbacks(:finish)
175
175
  end
176
176
 
177
- register_low_level_callbacks_on(@client)
177
+ register_low_level_callbacks
178
178
 
179
- @client.start_async
179
+ client.start_async
180
180
  rescue Slack::Web::Api::Error => e
181
181
  raise ConnectionError.new(e.message, e.response)
182
182
  end
@@ -187,7 +187,7 @@ class SlackBotServer::Bot
187
187
  def stop
188
188
  log "closing connection"
189
189
  @running = false
190
- @client.stop!
190
+ client.stop!
191
191
  log "closed"
192
192
  end
193
193
 
@@ -356,6 +356,8 @@ class SlackBotServer::Bot
356
356
 
357
357
  private
358
358
 
359
+ attr_reader :client
360
+
359
361
  def handle_message(data)
360
362
  run_callbacks(data.type, data)
361
363
  end
@@ -368,11 +370,11 @@ class SlackBotServer::Bot
368
370
  end
369
371
  end
370
372
 
371
- def register_low_level_callbacks_on(client)
373
+ def register_low_level_callbacks
372
374
  self.class.low_level_callbacks.each do |(type, callback)|
373
375
  client.on(type) do |*args|
374
376
  begin
375
- callback.call(*args)
377
+ instance_exec(*args, &callback)
376
378
  rescue => e
377
379
  log_error e
378
380
  end
@@ -381,7 +383,7 @@ class SlackBotServer::Bot
381
383
  end
382
384
 
383
385
  def is_im_channel?(id)
384
- @client.ims[id] != nil
386
+ client.ims[id] != nil
385
387
  end
386
388
 
387
389
  def bot_message?(data)
@@ -1,4 +1,4 @@
1
1
  module SlackBotServer
2
2
  # The current version of the +SlackBotServer+ framework
3
- VERSION = "0.4.5"
3
+ VERSION = "0.4.6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-bot-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Adam