socrates 0.1.6 → 0.1.7

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: f813438b75945834217c30d8bc6a5ef40ee9c1e4
4
- data.tar.gz: e7b0f2f3cb3aee495da7587452ec16f644e49921
3
+ metadata.gz: c9bb99fd80afa2c0115599cf6deb59a48689aa48
4
+ data.tar.gz: 7af67f0f859c82ff79fc2e59208b768dc41a9d16
5
5
  SHA512:
6
- metadata.gz: e83c6751e94f0f4019edbcffdc61669acd41c474e9502db5e2c0b501175e5aa64a2eb9c9bc0273c30b1d60a6f1a255d752a6a0ce977e3ebf786cbed4810a1531
7
- data.tar.gz: a0394070b283a41a9c265690a67a4edc001ff0b3f95f3793b3f2836824d83181a655c70186867ba71ca2bf5ba1071ee6cc1878319bf9de0100147d0e0c653f9f
6
+ metadata.gz: 1da101c9c7d1bb8ab6d77320a96038e7b83f0cc3d491bada410e11e315b7346aa1699abc2063cf52b300c4fff4d31da29d6172b4110dd25663e36dc872984186
7
+ data.tar.gz: dcbcafde4c22bc45e2e1a0d0b08228e3c5dcf64c1d83150e78b8803720b2a3beb30ae73089cfac72e460d926037459b8e4862fd1eb5677e4b768b6c3c4da6890
@@ -35,7 +35,7 @@ module Socrates
35
35
  users << User.new(id, name, Profile.new(first, last, email))
36
36
  end
37
37
 
38
- def users_list
38
+ def users_list(*)
39
39
  Response.new(users)
40
40
  end
41
41
 
@@ -34,7 +34,7 @@ module Socrates
34
34
  users << User.new(id, name, Profile.new(first, last, email))
35
35
  end
36
36
 
37
- def users_list
37
+ def users_list(*)
38
38
  Response.new(users)
39
39
  end
40
40
 
@@ -6,30 +6,41 @@ module Socrates
6
6
  end
7
7
 
8
8
  def client_id_from_context(context)
9
- context&.user
9
+ raise ArgumentError, "Context cannot be nil" if context.nil?
10
+ raise ArgumentError, "Expected context to respond to :user" unless context.respond_to?(:user)
11
+
12
+ context.user
10
13
  end
11
14
 
12
15
  def send_message(message, context:)
16
+ raise ArgumentError, "Expected context to respond to :channel" unless context.respond_to?(:channel)
17
+
13
18
  @real_time_client.message(text: message, channel: context.channel)
14
19
  end
15
20
 
16
21
  def send_direct_message(message, user, *)
17
- user = user.id if user.respond_to?(:id)
22
+ raise ArgumentError, "Expected user to respond to :id" unless user.respond_to?(:id)
18
23
 
19
24
  im_channel = lookup_im_channel(user)
20
25
 
21
26
  @real_time_client.message(text: message, channel: im_channel)
22
27
  end
23
28
 
24
- def users_list
29
+ def users_list(include_deleted: false, include_bots: false)
25
30
  client = @real_time_client.web_client
26
- client.users_list
31
+
32
+ client.users_list.tap do |response|
33
+ response.members.reject!(&:deleted?) unless include_deleted
34
+ response.members.reject!(&:is_bot?) unless include_bots
35
+ end
27
36
  end
28
37
 
29
38
  def lookup_email(context:)
39
+ raise ArgumentError, "Expected context to respond to :user" unless context.respond_to?(:user)
40
+
30
41
  client = @real_time_client.web_client
31
- info = client.users_info(user: context.user)
32
- info.present? ? info.user.profile.email : nil
42
+ info = client.users_info(user: context.user)
43
+ info.present? ? info.user.profile.email.presence : nil
33
44
  end
34
45
 
35
46
  private
@@ -18,13 +18,20 @@ module Socrates
18
18
  end
19
19
 
20
20
  def start
21
+ reply_to_messages = {}
22
+
21
23
  @slack_client.on :message do |data|
22
24
  # puts "> #{data}"
23
25
 
24
- # When first connecting, Slack may resend the last message. Ignore it...
25
- next if data.reply_to.present?
26
+ if data.reply_to.present?
27
+ # Stash this message away because we may need it later.
28
+ reply_to_messages[data.channel] = data.text
29
+ end
26
30
 
27
- @dispatcher.dispatch(data.text, context: data)
31
+ # Only dispatch the message if it does not match a previous reply_to message for the channel.
32
+ if reply_to_messages[data.channel] != data.text
33
+ @dispatcher.dispatch(data.text, context: data)
34
+ end
28
35
  end
29
36
 
30
37
  @slack_client.start!
@@ -46,7 +46,9 @@ module Socrates
46
46
  end
47
47
 
48
48
  def send_message(to:, message:)
49
- @logger.info %(#{client_id} send direct to #{to}: "#{format_for_logging(message)}")
49
+ displayable_to = to.respond_to?(:id) ? to.id : to
50
+
51
+ @logger.info %(#{client_id} send direct to #{displayable_to}: "#{format_for_logging(message)}")
50
52
  @adapter.send_direct_message(message, to, context: @context)
51
53
  end
52
54
 
@@ -1,3 +1,3 @@
1
1
  module Socrates
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socrates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler