socrates 0.1.19 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +36 -0
- data/.ruby-version +1 -1
- data/lib/socrates/bots/slack/ping.rb +28 -0
- data/lib/socrates/bots/slack.rb +19 -1
- data/lib/socrates/configuration.rb +3 -1
- data/lib/socrates/sample_states.rb +4 -5
- data/lib/socrates/version.rb +1 -1
- data/lib/socrates.rb +1 -0
- data/socrates.gemspec +2 -1
- metadata +21 -6
- data/circle.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e53d6a963e0727b1bd7ad8d42b330177aed491cf30445ec04258672d97e5f468
|
4
|
+
data.tar.gz: d316fc17f82718d619484e372dd2a81b8945c07a2018108cf3348842f815c93f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef55cc21dfb0d23284622656e73da3f2c6c808084324e1a7646d6ea6847a1c29bde36a0e9cd5b0b531a19e9fa6269400f614950017340c7dda431e1593d0e69f
|
7
|
+
data.tar.gz: 4513826a263c419af60c5b48a5f38204f28b17ce0ad3b937183f346c2d8431792a112035dc487c15885ea9960c2093f02ef06a4955fd17d749eab5ef4bab3f90
|
@@ -0,0 +1,36 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
parallelism: 1
|
5
|
+
working_directory: ~/socrates
|
6
|
+
docker:
|
7
|
+
- image: circleci/ruby:2.5.1
|
8
|
+
steps:
|
9
|
+
- checkout
|
10
|
+
|
11
|
+
# Restore bundle cache, with fallbacks to increase the likeliness of a cache hit
|
12
|
+
- restore_cache:
|
13
|
+
keys:
|
14
|
+
- gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
|
15
|
+
- gem-cache-{{ arch }}-{{ .Branch }}
|
16
|
+
- gem-cache
|
17
|
+
|
18
|
+
# Bundle install dependencies and remove any unused gems
|
19
|
+
- run: bundle install --path vendor/bundle --jobs=4 && bundle clean --force
|
20
|
+
|
21
|
+
# Store bundle cache
|
22
|
+
- save_cache:
|
23
|
+
key: gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
|
24
|
+
paths:
|
25
|
+
- vendor/bundle
|
26
|
+
|
27
|
+
# Rubocop compliance
|
28
|
+
- run: bundle exec rubocop
|
29
|
+
|
30
|
+
# Run RSpec in parallel, when parallelism > 1
|
31
|
+
- run: bundle exec rspec
|
32
|
+
|
33
|
+
# Save the test logs for debugging
|
34
|
+
- store_artifacts:
|
35
|
+
path: ./log/test.log
|
36
|
+
destination: test.log
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.1
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Socrates
|
2
|
+
module Bots
|
3
|
+
class Slack
|
4
|
+
class Ping
|
5
|
+
def initialize
|
6
|
+
logger = Logger.new(STDOUT)
|
7
|
+
# The ping is going to run every minute, so don't be too chatty
|
8
|
+
logger.level = Logger::WARN
|
9
|
+
|
10
|
+
@client = ::Slack::Web::Client.new(
|
11
|
+
token: ENV.fetch("SLACK_API_TOKEN"),
|
12
|
+
logger: logger
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def alive?
|
17
|
+
auth = client.auth_test
|
18
|
+
presence = client.users_getPresence(user: auth["user_id"])
|
19
|
+
presence.online?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :client
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/socrates/bots/slack.rb
CHANGED
@@ -30,7 +30,25 @@ module Socrates
|
|
30
30
|
@dispatcher.dispatch(data.text, context: data)
|
31
31
|
end
|
32
32
|
|
33
|
-
@slack_client.
|
33
|
+
@slack_client.start_async
|
34
|
+
|
35
|
+
ping = Ping.new
|
36
|
+
loop do
|
37
|
+
sleep 60
|
38
|
+
next if ping.alive?
|
39
|
+
|
40
|
+
alert "Slack RTC has gone offline; restarting it"
|
41
|
+
@slack_client.stop! if @slack_client.started?
|
42
|
+
sleep 1 # give the websocket a chance to completely disconnect
|
43
|
+
@slack_client.start_async
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def alert(message)
|
50
|
+
Socrates.config.logger.warn(message)
|
51
|
+
Socrates.config.warn_handler.call(message)
|
34
52
|
end
|
35
53
|
end
|
36
54
|
end
|
@@ -17,7 +17,8 @@ module Socrates
|
|
17
17
|
attr_accessor :error_message
|
18
18
|
attr_accessor :expired_timeout # seconds
|
19
19
|
attr_accessor :logger
|
20
|
-
attr_accessor :error_handler # a callable
|
20
|
+
attr_accessor :error_handler # a callable like ->(String, Exception) { ... }
|
21
|
+
attr_accessor :warn_handler # a callable like ->(String) { ... }
|
21
22
|
|
22
23
|
def initialize
|
23
24
|
@storage = Storage::Memory.new
|
@@ -25,6 +26,7 @@ module Socrates
|
|
25
26
|
@expired_timeout = 30.minutes
|
26
27
|
@logger = Socrates::Logger.default
|
27
28
|
@error_handler = proc { |_message, _error| }
|
29
|
+
@warn_handler = proc { |_message| }
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -141,11 +141,10 @@ module Socrates
|
|
141
141
|
def calculate_age
|
142
142
|
today = Time.current.to_date
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
end
|
144
|
+
age = today.year - birth_date.year
|
145
|
+
age -= 1 if today.month < birth_date.month || (today.month == birth_date.month && birth_date.day > today.day)
|
146
|
+
|
147
|
+
age
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
data/lib/socrates/version.rb
CHANGED
data/lib/socrates.rb
CHANGED
data/socrates.gemspec
CHANGED
@@ -26,7 +26,8 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.16"
|
27
27
|
spec.add_development_dependency "rake", "~> 12.3"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.7"
|
29
|
-
spec.add_development_dependency "rubocop", "
|
29
|
+
spec.add_development_dependency "rubocop", "0.54"
|
30
|
+
spec.add_development_dependency "simplecov", "~> 0.16.1"
|
30
31
|
spec.add_development_dependency "timecop", "~> 0.9"
|
31
32
|
|
32
33
|
spec.add_dependency "activesupport", ">= 5.1.4"
|
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.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,18 +54,32 @@ dependencies:
|
|
54
54
|
version: '3.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.54'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.54'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: 0.16.1
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 0.16.1
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: timecop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,6 +172,7 @@ executables:
|
|
158
172
|
extensions: []
|
159
173
|
extra_rdoc_files: []
|
160
174
|
files:
|
175
|
+
- ".circleci/config.yml"
|
161
176
|
- ".gitignore"
|
162
177
|
- ".rspec"
|
163
178
|
- ".rubocop.yml"
|
@@ -167,7 +182,6 @@ files:
|
|
167
182
|
- Rakefile
|
168
183
|
- bin/console
|
169
184
|
- bin/setup
|
170
|
-
- circle.yml
|
171
185
|
- exe/socrates
|
172
186
|
- lib/socrates.rb
|
173
187
|
- lib/socrates/adapters/adapter.rb
|
@@ -177,6 +191,7 @@ files:
|
|
177
191
|
- lib/socrates/adapters/stubs.rb
|
178
192
|
- lib/socrates/bots/cli.rb
|
179
193
|
- lib/socrates/bots/slack.rb
|
194
|
+
- lib/socrates/bots/slack/ping.rb
|
180
195
|
- lib/socrates/configuration.rb
|
181
196
|
- lib/socrates/core/dispatcher.rb
|
182
197
|
- lib/socrates/core/session.rb
|
@@ -211,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
226
|
version: '0'
|
212
227
|
requirements: []
|
213
228
|
rubyforge_project:
|
214
|
-
rubygems_version: 2.7.
|
229
|
+
rubygems_version: 2.7.6
|
215
230
|
signing_key:
|
216
231
|
specification_version: 4
|
217
232
|
summary: A micro-framework for building stateful conversational bots.
|