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 +4 -4
- data/lib/socrates/adapters/console_adapter.rb +1 -1
- data/lib/socrates/adapters/memory_adapter.rb +1 -1
- data/lib/socrates/adapters/slack_adapter.rb +17 -6
- data/lib/socrates/bots/slack_bot.rb +10 -3
- data/lib/socrates/core/state.rb +3 -1
- data/lib/socrates/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9bb99fd80afa2c0115599cf6deb59a48689aa48
|
4
|
+
data.tar.gz: 7af67f0f859c82ff79fc2e59208b768dc41a9d16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da101c9c7d1bb8ab6d77320a96038e7b83f0cc3d491bada410e11e315b7346aa1699abc2063cf52b300c4fff4d31da29d6172b4110dd25663e36dc872984186
|
7
|
+
data.tar.gz: dcbcafde4c22bc45e2e1a0d0b08228e3c5dcf64c1d83150e78b8803720b2a3beb30ae73089cfac72e460d926037459b8e4862fd1eb5677e4b768b6c3c4da6890
|
@@ -6,30 +6,41 @@ module Socrates
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def client_id_from_context(context)
|
9
|
-
context
|
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
|
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
|
-
|
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
|
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
|
-
|
25
|
-
|
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
|
-
|
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!
|
data/lib/socrates/core/state.rb
CHANGED
@@ -46,7 +46,9 @@ module Socrates
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def send_message(to:, message:)
|
49
|
-
|
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
|
|
data/lib/socrates/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|