waylon-core 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.roxanne.yml +5 -1
- data/.rubocop.yml +8 -1
- data/.ruby-version +1 -1
- data/Gemfile.lock +42 -44
- data/README.md +1 -1
- data/lib/waylon/condition.rb +29 -1
- data/lib/waylon/conditions/black_hole.rb +34 -0
- data/lib/waylon/conditions/regex.rb +8 -0
- data/lib/waylon/config.rb +4 -3
- data/lib/waylon/core.rb +6 -0
- data/lib/waylon/group.rb +1 -1
- data/lib/waylon/logger.rb +14 -7
- data/lib/waylon/message.rb +20 -0
- data/lib/waylon/route.rb +1 -1
- data/lib/waylon/routes/black_hole.rb +17 -0
- data/lib/waylon/rspec/matchers/route_matcher.rb +7 -0
- data/lib/waylon/rspec/skill.rb +1 -1
- data/lib/waylon/rspec/test_message.rb +2 -0
- data/lib/waylon/rspec/test_sense.rb +21 -15
- data/lib/waylon/rspec/test_server.rb +4 -1
- data/lib/waylon/rspec/test_user.rb +2 -2
- data/lib/waylon/rspec/test_worker.rb +2 -2
- data/lib/waylon/sense.rb +5 -6
- data/lib/waylon/sense_registry.rb +2 -0
- data/lib/waylon/services/ping.rb +30 -0
- data/lib/waylon/skill.rb +54 -21
- data/lib/waylon/skill_registry.rb +47 -10
- data/lib/waylon/skills/default.rb +5 -0
- data/lib/waylon/skills/diagnostics.rb +60 -0
- data/lib/waylon/skills/fun.rb +5 -2
- data/lib/waylon/skills/groups.rb +173 -0
- data/lib/waylon/skills/help.rb +174 -0
- data/lib/waylon/user.rb +5 -0
- data/lib/waylon/version.rb +1 -1
- data/lib/waylon/webhook.rb +24 -25
- data/lib/waylon/webhook_registry.rb +32 -0
- data/lib/waylon.rb +3 -0
- data/scripts/release.sh +7 -0
- data/scripts/test.sh +1 -1
- data/waylon-core.gemspec +1 -1
- metadata +16 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb29b523a0f093d01b8a9abdf5cd23d54b2815ae0430b81f8e670680959d02f6
|
4
|
+
data.tar.gz: 4c79ff418934e61e9063db9568d2397409117afd2a7519d9b4c9348233991667
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 505ad2082ae04e37478e03637b13952d81d8c26c9e8107eeded3b4247ae25f776f7d1d7d4a4fd0739edd670ba74256e33adbd22c6f46957f528c820ef371bfce
|
7
|
+
data.tar.gz: a9c1b1de874c75d7d909a83904e46360236334f652dae8ad059d5adf8b405315030245420dba3a8e159b21d99d221a502d30cfe439f2b2b77411ff06261af695
|
data/.roxanne.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -21,7 +21,10 @@ Gemspec/RequireMFA:
|
|
21
21
|
Enabled: false
|
22
22
|
|
23
23
|
Metrics/AbcSize:
|
24
|
-
Max: 19
|
24
|
+
Max: 19.5
|
25
|
+
|
26
|
+
Metrics/ClassLength:
|
27
|
+
Max: 200
|
25
28
|
|
26
29
|
Metrics/CyclomaticComplexity:
|
27
30
|
Max: 9
|
@@ -32,7 +35,11 @@ Metrics/PerceivedComplexity:
|
|
32
35
|
Metrics/MethodLength:
|
33
36
|
Max: 20
|
34
37
|
|
38
|
+
Metrics/ParameterLists:
|
39
|
+
Max: 6
|
40
|
+
|
35
41
|
Metrics/BlockLength:
|
36
42
|
Exclude:
|
37
43
|
- "**/*_spec.rb"
|
38
44
|
- "*.gemspec"
|
45
|
+
- "lib/waylon/rspec/matchers/**/*.rb"
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
waylon-core (0.1.
|
4
|
+
waylon-core (0.1.4)
|
5
5
|
addressable (~> 2.8)
|
6
6
|
faraday (~> 1.8)
|
7
7
|
i18n (~> 1.8)
|
@@ -16,10 +16,10 @@ GEM
|
|
16
16
|
addressable (2.8.0)
|
17
17
|
public_suffix (>= 2.0.2, < 5.0)
|
18
18
|
ast (2.4.2)
|
19
|
-
concurrent-ruby (1.1.
|
20
|
-
diff-lcs (1.
|
19
|
+
concurrent-ruby (1.1.10)
|
20
|
+
diff-lcs (1.5.0)
|
21
21
|
docile (1.4.0)
|
22
|
-
faraday (1.
|
22
|
+
faraday (1.10.0)
|
23
23
|
faraday-em_http (~> 1.0)
|
24
24
|
faraday-em_synchrony (~> 1.0)
|
25
25
|
faraday-excon (~> 1.1)
|
@@ -35,72 +35,71 @@ GEM
|
|
35
35
|
faraday-em_synchrony (1.0.0)
|
36
36
|
faraday-excon (1.1.0)
|
37
37
|
faraday-httpclient (1.0.1)
|
38
|
-
faraday-multipart (1.0.
|
38
|
+
faraday-multipart (1.0.3)
|
39
39
|
multipart-post (>= 1.2, < 3)
|
40
40
|
faraday-net_http (1.0.1)
|
41
41
|
faraday-net_http_persistent (1.2.0)
|
42
42
|
faraday-patron (1.0.0)
|
43
43
|
faraday-rack (1.0.0)
|
44
44
|
faraday-retry (1.0.3)
|
45
|
-
i18n (1.
|
45
|
+
i18n (1.10.0)
|
46
46
|
concurrent-ruby (~> 1.0)
|
47
|
-
json (2.6.
|
48
|
-
moneta (1.
|
47
|
+
json (2.6.2)
|
48
|
+
moneta (1.5.1)
|
49
49
|
mono_logger (1.1.1)
|
50
50
|
multi_json (1.15.0)
|
51
51
|
multipart-post (2.1.1)
|
52
52
|
mustermann (1.1.1)
|
53
53
|
ruby2_keywords (~> 0.0.1)
|
54
54
|
nio4r (2.5.8)
|
55
|
-
parallel (1.
|
56
|
-
parser (3.
|
55
|
+
parallel (1.22.1)
|
56
|
+
parser (3.1.2.0)
|
57
57
|
ast (~> 2.4.1)
|
58
|
-
public_suffix (4.0.
|
59
|
-
puma (5.
|
58
|
+
public_suffix (4.0.7)
|
59
|
+
puma (5.6.4)
|
60
60
|
nio4r (~> 2.0)
|
61
61
|
rack (2.2.3)
|
62
|
-
rack-protection (2.
|
62
|
+
rack-protection (2.2.0)
|
63
63
|
rack
|
64
|
-
rainbow (3.
|
64
|
+
rainbow (3.1.1)
|
65
65
|
rake (13.0.6)
|
66
|
-
redis (4.
|
67
|
-
redis-namespace (1.8.
|
66
|
+
redis (4.6.0)
|
67
|
+
redis-namespace (1.8.2)
|
68
68
|
redis (>= 3.0.4)
|
69
|
-
regexp_parser (2.
|
70
|
-
resque (2.2.
|
69
|
+
regexp_parser (2.4.0)
|
70
|
+
resque (2.2.1)
|
71
71
|
mono_logger (~> 1.0)
|
72
72
|
multi_json (~> 1.0)
|
73
73
|
redis-namespace (~> 1.6)
|
74
74
|
sinatra (>= 0.9.2)
|
75
|
-
vegas (~> 0.1.2)
|
76
75
|
rexml (3.2.5)
|
77
|
-
rspec (3.
|
78
|
-
rspec-core (~> 3.
|
79
|
-
rspec-expectations (~> 3.
|
80
|
-
rspec-mocks (~> 3.
|
81
|
-
rspec-core (3.
|
82
|
-
rspec-support (~> 3.
|
83
|
-
rspec-expectations (3.
|
76
|
+
rspec (3.11.0)
|
77
|
+
rspec-core (~> 3.11.0)
|
78
|
+
rspec-expectations (~> 3.11.0)
|
79
|
+
rspec-mocks (~> 3.11.0)
|
80
|
+
rspec-core (3.11.0)
|
81
|
+
rspec-support (~> 3.11.0)
|
82
|
+
rspec-expectations (3.11.0)
|
84
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
-
rspec-support (~> 3.
|
86
|
-
rspec-mocks (3.
|
84
|
+
rspec-support (~> 3.11.0)
|
85
|
+
rspec-mocks (3.11.1)
|
87
86
|
diff-lcs (>= 1.2.0, < 2.0)
|
88
|
-
rspec-support (~> 3.
|
89
|
-
rspec-support (3.
|
90
|
-
rubocop (1.
|
87
|
+
rspec-support (~> 3.11.0)
|
88
|
+
rspec-support (3.11.0)
|
89
|
+
rubocop (1.29.1)
|
91
90
|
parallel (~> 1.10)
|
92
|
-
parser (>= 3.
|
91
|
+
parser (>= 3.1.0.0)
|
93
92
|
rainbow (>= 2.2.2, < 4.0)
|
94
93
|
regexp_parser (>= 1.8, < 3.0)
|
95
|
-
rexml
|
96
|
-
rubocop-ast (>= 1.
|
94
|
+
rexml (>= 3.2.5, < 4.0)
|
95
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
97
96
|
ruby-progressbar (~> 1.7)
|
98
97
|
unicode-display_width (>= 1.4.0, < 3.0)
|
99
|
-
rubocop-ast (1.
|
100
|
-
parser (>= 3.
|
98
|
+
rubocop-ast (1.18.0)
|
99
|
+
parser (>= 3.1.1.0)
|
101
100
|
rubocop-rake (0.6.0)
|
102
101
|
rubocop (~> 1.0)
|
103
|
-
rubocop-rspec (2.
|
102
|
+
rubocop-rspec (2.11.1)
|
104
103
|
rubocop (~> 1.19)
|
105
104
|
ruby-progressbar (1.11.0)
|
106
105
|
ruby2_keywords (0.0.5)
|
@@ -109,25 +108,24 @@ GEM
|
|
109
108
|
simplecov-html (~> 0.11)
|
110
109
|
simplecov_json_formatter (~> 0.1)
|
111
110
|
simplecov-html (0.12.3)
|
112
|
-
simplecov_json_formatter (0.1.
|
113
|
-
sinatra (2.
|
111
|
+
simplecov_json_formatter (0.1.4)
|
112
|
+
sinatra (2.2.0)
|
114
113
|
mustermann (~> 1.0)
|
115
114
|
rack (~> 2.2)
|
116
|
-
rack-protection (= 2.
|
115
|
+
rack-protection (= 2.2.0)
|
117
116
|
tilt (~> 2.0)
|
118
117
|
tilt (2.0.10)
|
119
118
|
unicode-display_width (2.1.0)
|
120
|
-
vegas (0.1.11)
|
121
|
-
rack (>= 1.0.0)
|
122
119
|
webrick (1.7.0)
|
123
120
|
yard (0.9.27)
|
124
121
|
webrick (~> 1.7.0)
|
125
122
|
|
126
123
|
PLATFORMS
|
127
124
|
arm64-darwin-21
|
125
|
+
x86_64-linux
|
128
126
|
|
129
127
|
DEPENDENCIES
|
130
|
-
bundler (~> 2.
|
128
|
+
bundler (~> 2.3)
|
131
129
|
rake (~> 13.0)
|
132
130
|
rspec (~> 3.10)
|
133
131
|
rubocop (~> 1.23)
|
@@ -138,4 +136,4 @@ DEPENDENCIES
|
|
138
136
|
yard (~> 0.9, >= 0.9.27)
|
139
137
|
|
140
138
|
BUNDLED WITH
|
141
|
-
2.
|
139
|
+
2.3.10
|
data/README.md
CHANGED
@@ -44,7 +44,7 @@ Alone, this library isn't super useful for running a bot, but it does include a
|
|
44
44
|
|
45
45
|
## Development
|
46
46
|
|
47
|
-
Waylon's development pipeline makes heavy use of [RSpec](https://rspec.info/) for testing (and [SimpleCov](https://github.com/simplecov-ruby/simplecov) for reporting on coverage), [Rubocop](https://rubocop.org/) for linting/format checking, [YARD](https://yardoc.org/) for documentation, and [
|
47
|
+
Waylon's development pipeline makes heavy use of [RSpec](https://rspec.info/) for testing (and [SimpleCov](https://github.com/simplecov-ruby/simplecov) for reporting on coverage), [Rubocop](https://rubocop.org/) for linting/format checking, [YARD](https://yardoc.org/) for documentation, and [RoxanneCI](https://github.com/apps/roxanneci) for CI. Most of this is built-in and will work out-of-the-box for GitHub PRs.
|
48
48
|
|
49
49
|
To get started locally, after checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and linting. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
50
|
|
data/lib/waylon/condition.rb
CHANGED
@@ -10,19 +10,37 @@ module Waylon
|
|
10
10
|
# @param action [Symbol] The method to call if the condition matches
|
11
11
|
# @param allowed_groups [Array<Symbol>] The group names allowed to use this action
|
12
12
|
# @param help [String] Optional help text to describe usage for this action
|
13
|
-
|
13
|
+
# @param mention_only [Boolean] Only applies to messages that directly mention (or IM) this bot
|
14
|
+
# rubocop:disable Style/OptionalBooleanParameter
|
15
|
+
def initialize(mechanism, action, allowed_groups, help = nil, mention_only = true)
|
14
16
|
@mechanism = mechanism
|
15
17
|
@action = action
|
16
18
|
@allowed_groups = allowed_groups
|
17
19
|
@help = help
|
20
|
+
@mention_only = mention_only
|
18
21
|
end
|
22
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
19
23
|
|
20
24
|
# Placeholder for determining if this condition applies to the given input
|
21
25
|
# @param _input [Waylon::Message] The input message
|
26
|
+
# @return [Boolean]
|
22
27
|
def matches?(_input)
|
23
28
|
false
|
24
29
|
end
|
25
30
|
|
31
|
+
# Is this condition only valid for Messages that directly mention the bot?
|
32
|
+
# @return [Boolean]
|
33
|
+
def mention_only?
|
34
|
+
@mention_only
|
35
|
+
end
|
36
|
+
|
37
|
+
# Placeholder for optionally providing _named_ tokens
|
38
|
+
# @param _input [String] The message content
|
39
|
+
# @return [Hash<String,Object>]
|
40
|
+
def named_tokens(_input)
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
|
26
44
|
# Checks if a user is allowed based on this condition
|
27
45
|
# @param user [Waylon::User] abstract user
|
28
46
|
def permits?(user)
|
@@ -44,6 +62,16 @@ module Waylon
|
|
44
62
|
permitted
|
45
63
|
end
|
46
64
|
|
65
|
+
# Determines of a message complies with the {#mention_only?} setting for this condition
|
66
|
+
# @param message [Waylon::Message] The received message
|
67
|
+
# @return [Boolean]
|
68
|
+
def properly_mentions?(message)
|
69
|
+
return true unless mention_only?
|
70
|
+
|
71
|
+
message.to_bot?
|
72
|
+
# (mention_only? && message.to_bot?) || (!mention_only? && !message.to_bot?)
|
73
|
+
end
|
74
|
+
|
47
75
|
# Tokens is used to provide details about the message input to the action
|
48
76
|
# @param _input [String] The message content as text
|
49
77
|
# @return [Array<String>] The tokens extracted from the input message
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Waylon
|
4
|
+
module Conditions
|
5
|
+
# A pre-made catch-all condition for ignoring messages
|
6
|
+
class BlackHole < Condition
|
7
|
+
# Overrides normal Condition initialization to force a specific action
|
8
|
+
def initialize(*_args) # rubocop:disable Lint/MissingSuper
|
9
|
+
@mechanism = nil
|
10
|
+
@action = :ignore
|
11
|
+
@allowed_groups = [:everyone]
|
12
|
+
@help = ""
|
13
|
+
end
|
14
|
+
|
15
|
+
# Matches any input (since the Default route, when used, should always function)
|
16
|
+
# @return [Boolean]
|
17
|
+
def matches?(_input)
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
# Permits any user (since the Default route, when used, should always function)
|
22
|
+
# @return [Boolean]
|
23
|
+
def permits?(_user)
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Just provides back all input as a single token
|
28
|
+
# @return [Array<String>]
|
29
|
+
def tokens(input)
|
30
|
+
[input]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -17,6 +17,14 @@ module Waylon
|
|
17
17
|
def tokens(input)
|
18
18
|
@mechanism.match(input).to_a[1..]
|
19
19
|
end
|
20
|
+
|
21
|
+
# Provides the _named_ regular expression match groups as a hash
|
22
|
+
# @param input [String] The message text
|
23
|
+
# @return [Hash<Symbol,String>] The named regular expression match groups
|
24
|
+
def named_tokens(input)
|
25
|
+
match_data = @mechanism.match(input)
|
26
|
+
match_data.names.to_h { |n| [n.to_sym, match_data[n]] }
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
data/lib/waylon/config.rb
CHANGED
@@ -23,7 +23,7 @@ module Waylon
|
|
23
23
|
true
|
24
24
|
end
|
25
25
|
|
26
|
-
# A list of emails specified via the
|
26
|
+
# A list of emails specified via the GLOBAL_ADMINS environment variable
|
27
27
|
# @return [Array<String>] a list of emails
|
28
28
|
def admins
|
29
29
|
admin_emails = self["global.admins"]
|
@@ -32,15 +32,16 @@ module Waylon
|
|
32
32
|
|
33
33
|
# Load in the config from env variables
|
34
34
|
# @return [Boolean] Was the configuration loaded?
|
35
|
-
def load_env
|
35
|
+
def load_env # rubocop:disable Metrics/AbcSize
|
36
36
|
@schema ||= {}
|
37
37
|
self["global.log.level"] = ENV.fetch("LOG_LEVEL", "info")
|
38
38
|
self["global.redis.host"] = ENV.fetch("REDIS_HOST", "redis")
|
39
39
|
self["global.redis.port"] = ENV.fetch("REDIS_PORT", "6379")
|
40
|
+
self["global.admins"] = ENV.fetch("GLOBAL_ADMINS", "")
|
40
41
|
ENV.keys.grep(/CONF_/).each do |env_key|
|
41
42
|
conf_key = env_key.downcase.split("_")[1..].join(".")
|
42
43
|
::Waylon::Logger.log("Attempting to set #{conf_key} from #{env_key}", :debug)
|
43
|
-
self[conf_key] = ENV
|
44
|
+
self[conf_key] = ENV.fetch(env_key, nil)
|
44
45
|
end
|
45
46
|
true
|
46
47
|
end
|
data/lib/waylon/core.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# Standard Library dependencies
|
4
4
|
require "base64"
|
5
|
+
require "benchmark"
|
5
6
|
require "digest"
|
6
7
|
require "English"
|
7
8
|
require "fileutils"
|
@@ -21,6 +22,7 @@ require "i18n"
|
|
21
22
|
require "json"
|
22
23
|
require "moneta"
|
23
24
|
require "resque"
|
25
|
+
require "sinatra"
|
24
26
|
|
25
27
|
# Internal requirements
|
26
28
|
require "waylon/version"
|
@@ -39,8 +41,12 @@ require "waylon/sense"
|
|
39
41
|
require "waylon/skill_registry"
|
40
42
|
require "waylon/skill"
|
41
43
|
require "waylon/user"
|
44
|
+
require "waylon/conditions/black_hole"
|
42
45
|
require "waylon/conditions/default"
|
43
46
|
require "waylon/conditions/permission_denied"
|
44
47
|
require "waylon/conditions/regex"
|
48
|
+
require "waylon/routes/black_hole"
|
45
49
|
require "waylon/routes/default"
|
46
50
|
require "waylon/routes/permission_denied"
|
51
|
+
require "waylon/webhook"
|
52
|
+
require "waylon/webhook_registry"
|
data/lib/waylon/group.rb
CHANGED
data/lib/waylon/logger.rb
CHANGED
@@ -6,7 +6,7 @@ module Waylon
|
|
6
6
|
# The log level as defined in the global Config singleton
|
7
7
|
# @return [String] The current log level
|
8
8
|
def self.level
|
9
|
-
Config.instance["global.log.level"]
|
9
|
+
Config.instance["global.log.level"] || "info"
|
10
10
|
end
|
11
11
|
|
12
12
|
# Abstraction for sending logs to the logger at some level
|
@@ -19,12 +19,18 @@ module Waylon
|
|
19
19
|
# Provides an easy way to access the underlying logger
|
20
20
|
# @return [Logger] The Logger instance
|
21
21
|
def self.logger
|
22
|
-
|
22
|
+
@logger ||= json_logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.logger=(logger)
|
26
|
+
@logger = logger
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
def self.json_logger
|
30
|
+
a_logger = ::Logger.new($stderr)
|
31
|
+
a_logger.level = level
|
32
|
+
a_logger.progname = "Waylon"
|
33
|
+
a_logger.formatter = proc do |severity, datetime, progname, msg|
|
28
34
|
json_data = JSON.dump(
|
29
35
|
ts: datetime,
|
30
36
|
severity: severity.ljust(5).to_s,
|
@@ -35,7 +41,8 @@ module Waylon
|
|
35
41
|
)
|
36
42
|
"#{json_data}\n"
|
37
43
|
end
|
38
|
-
|
44
|
+
|
45
|
+
a_logger
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
data/lib/waylon/message.rb
CHANGED
@@ -9,9 +9,29 @@ module Waylon
|
|
9
9
|
nil
|
10
10
|
end
|
11
11
|
|
12
|
+
# Message body
|
13
|
+
def body
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
12
17
|
# Message channel (meant to be overwritten by mixing classes)
|
13
18
|
def channel
|
14
19
|
nil
|
15
20
|
end
|
21
|
+
|
22
|
+
# Does the Message mention the bot (meant to be overwritten by mixing classes)
|
23
|
+
def mentions_bot?
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
# Is the Message a private/direct Message?
|
28
|
+
def private?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_bot?
|
33
|
+
# private? || mentions_bot?
|
34
|
+
true
|
35
|
+
end
|
16
36
|
end
|
17
37
|
end
|
data/lib/waylon/route.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Waylon
|
4
|
+
module Routes
|
5
|
+
# The route for unroutable events
|
6
|
+
class BlackHole < Route
|
7
|
+
def initialize(
|
8
|
+
name: "black_hole",
|
9
|
+
destination: Skills::Default,
|
10
|
+
condition: Conditions::BlackHole.new,
|
11
|
+
priority: 0
|
12
|
+
)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -36,6 +36,13 @@ module Waylon
|
|
36
36
|
chain :to do |method_name|
|
37
37
|
@method_name = method_name
|
38
38
|
end
|
39
|
+
|
40
|
+
description do
|
41
|
+
result = "route \"#{expected}\""
|
42
|
+
result += " to action \"#{@method_name}\"" if @method_name
|
43
|
+
result += " while a member of \"#{@group}\"" if @group
|
44
|
+
result
|
45
|
+
end
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
data/lib/waylon/rspec/skill.rb
CHANGED
@@ -22,14 +22,14 @@ module Waylon
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Overrides the Sense.enqueue class method to avoid Resque
|
25
|
-
def self.enqueue(route,
|
25
|
+
def self.enqueue(route, request)
|
26
26
|
details = {
|
27
27
|
"sense" => self,
|
28
|
-
"
|
29
|
-
"
|
28
|
+
"request" => request,
|
29
|
+
"route" => route.name
|
30
30
|
}
|
31
31
|
|
32
|
-
fake_queue.push [route.destination,
|
32
|
+
fake_queue.push [route.destination, details]
|
33
33
|
end
|
34
34
|
|
35
35
|
# Allows access to the fake version of Resque
|
@@ -50,15 +50,10 @@ module Waylon
|
|
50
50
|
@message_list ||= []
|
51
51
|
end
|
52
52
|
|
53
|
-
#
|
54
|
-
# @
|
55
|
-
|
56
|
-
|
57
|
-
message_list << message_details
|
58
|
-
message_id = message_list.size - 1
|
59
|
-
msg = message_class.new(message_id)
|
60
|
-
route = SkillRegistry.instance.route(msg) || SkillRegistry.instance.default_route
|
61
|
-
enqueue(route, msg.id, msg.text)
|
53
|
+
# Provides a way to use an initial request to reconstitute a Sense-specific Message
|
54
|
+
# @return [Waylon::Message]
|
55
|
+
def self.message_from_request(request)
|
56
|
+
message_class.new(message_list.size - 1, request)
|
62
57
|
end
|
63
58
|
|
64
59
|
# Emulates reactions by sending a message with the reaction type
|
@@ -66,7 +61,7 @@ module Waylon
|
|
66
61
|
# @param type [Symbol,String] The type of reaction to send
|
67
62
|
# @return [void]
|
68
63
|
def self.react(request, type)
|
69
|
-
msg =
|
64
|
+
msg = message_from_request(request)
|
70
65
|
msg.channel.post_message(":#{type}:")
|
71
66
|
end
|
72
67
|
|
@@ -81,10 +76,21 @@ module Waylon
|
|
81
76
|
# @param text [String] The message content to send in response to the request
|
82
77
|
# @return [void]
|
83
78
|
def self.reply(request, text)
|
84
|
-
msg =
|
79
|
+
msg = message_from_request(request)
|
85
80
|
msg.channel.post_message(text)
|
86
81
|
end
|
87
82
|
|
83
|
+
# Receives incoming message details and places work on a queue to be performed by a Skill
|
84
|
+
# @param message_details [Hash] The details necessary for creating a TestMessage
|
85
|
+
# @return [void]
|
86
|
+
def self.run(message_details)
|
87
|
+
message_list << message_details
|
88
|
+
message_id = message_list.size - 1
|
89
|
+
msg = message_class.new(message_id)
|
90
|
+
route = SkillRegistry.route(msg) || SkillRegistry.instance.default_route(msg)
|
91
|
+
enqueue(route, message_details)
|
92
|
+
end
|
93
|
+
|
88
94
|
# Provides all message text sent _by_ Waylon
|
89
95
|
# @return [Array<String>]
|
90
96
|
def self.sent_messages
|
@@ -41,7 +41,10 @@ end
|
|
41
41
|
Waylon::RSpec::TestChannel.find_or_create("random")
|
42
42
|
|
43
43
|
# Load demo skills here
|
44
|
+
require "waylon/skills/diagnostics"
|
44
45
|
require "waylon/skills/fun"
|
46
|
+
require "waylon/skills/groups"
|
47
|
+
require "waylon/skills/help"
|
45
48
|
|
46
49
|
# Handle demo chat REPL
|
47
50
|
def adminuser
|
@@ -101,7 +104,7 @@ def handle_input(body, from: this_user, privately: true)
|
|
101
104
|
else
|
102
105
|
message_count = Waylon::RSpec::TestSense.sent_messages.size
|
103
106
|
|
104
|
-
Waylon::RSpec::TestSense.
|
107
|
+
Waylon::RSpec::TestSense.perform(msg_details(body, from, privately))
|
105
108
|
Waylon::RSpec::TestWorker.handle(Waylon::RSpec::TestSense.fake_queue)
|
106
109
|
result = Waylon::RSpec::TestSense.sent_messages[message_count..].join("\n")
|
107
110
|
puts("(@#{Waylon::RSpec::TestUser.whoami.handle}) >> #{result}")
|
@@ -147,8 +147,8 @@ module Waylon
|
|
147
147
|
# @api private
|
148
148
|
# @return [String] A generated email address
|
149
149
|
def self.email_from_name(name)
|
150
|
-
if ENV
|
151
|
-
ENV
|
150
|
+
if ENV.fetch("USER_EMAIL", nil) && name == "homer.simpson"
|
151
|
+
ENV.fetch("USER_EMAIL", nil)
|
152
152
|
else
|
153
153
|
"#{name.downcase.gsub(/[\s_-]/, ".")}@example.com"
|
154
154
|
end
|
@@ -7,8 +7,8 @@ module Waylon
|
|
7
7
|
# Instructs the worker to grab an item off the Queue and run it
|
8
8
|
# @param queue [Queue] The queue that contains work to be done
|
9
9
|
def self.handle(queue)
|
10
|
-
skill,
|
11
|
-
skill.perform(
|
10
|
+
skill, details = queue.pop
|
11
|
+
skill.perform(details)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|