waylon-core 0.1.2 → 0.1.5

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
  SHA256:
3
- metadata.gz: bf4a171a8420b5e982d54cf24b991a7ae667f3aa93f08b361d10ac28d9726207
4
- data.tar.gz: 63982b47f1c05134c4fa5c69d07c4e05e8a1d748c245a4d7bd0695dabe4171c5
3
+ metadata.gz: 443bc0d5a5a87010e8c006d2882631ef323ed5c06ed343e6ca1f5cb080042c33
4
+ data.tar.gz: 10812a5cd59babb662a9ef73f0c68146c2e736605f383047e08150375057c78a
5
5
  SHA512:
6
- metadata.gz: 17a2baf807fd68312c76da6d9d1ca328ed5e5fec065711a7b8ce14a7d86850843d3ce2f6cfa3d4ea26f3c3ce30f329796427deeb98dcd6df77ec181da0afaf3f
7
- data.tar.gz: 3edb93a7e82655d44d553687493d11a0a7559b6ae318ffb92051d481872c882baa2c6191a88e96ddd3936df278844e1caee97837f15523fd2158275d0a84eb03
6
+ metadata.gz: a2a5f869c3bec9cac04882f15b6d5241468d88bdc2c6d3c205f6db920041f6837c719dbf21812fb450d4a1024819391cbbf184aece064a3eeebea2ef2d8dde22
7
+ data.tar.gz: de895fbc4f2718a3c5f016f3f76fbe6d2abcfa22885a2a0bfc84968c937a60403e7b8b2394e6e911bf170c05d6d075daa97588420eced57978b7dad157570991
data/.roxanne.yml CHANGED
@@ -1,4 +1,8 @@
1
1
  version: 1.0
2
2
  stages:
3
3
  test:
4
- image: ruby:3.0
4
+ image: ruby:3.1
5
+ release:
6
+ image: ruby:3.1
7
+ only:
8
+ - main
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.0
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.2)
4
+ waylon-core (0.1.5)
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.9)
19
+ concurrent-ruby (1.1.10)
20
20
  diff-lcs (1.5.0)
21
21
  docile (1.4.0)
22
- faraday (1.9.3)
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.2)
39
- multipart-post (>= 1.2, < 3)
38
+ faraday-multipart (1.0.4)
39
+ multipart-post (~> 2)
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.8.11)
45
+ i18n (1.10.0)
46
46
  concurrent-ruby (~> 1.0)
47
- json (2.6.1)
48
- moneta (1.4.2)
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
- multipart-post (2.1.1)
51
+ multipart-post (2.2.0)
52
52
  mustermann (1.1.1)
53
53
  ruby2_keywords (~> 0.0.1)
54
54
  nio4r (2.5.8)
55
- parallel (1.21.0)
56
- parser (3.1.0.0)
55
+ parallel (1.22.1)
56
+ parser (3.1.2.0)
57
57
  ast (~> 2.4.1)
58
- public_suffix (4.0.6)
59
- puma (5.5.2)
58
+ public_suffix (4.0.7)
59
+ puma (5.6.4)
60
60
  nio4r (~> 2.0)
61
- rack (2.2.3)
62
- rack-protection (2.1.0)
61
+ rack (2.2.3.1)
62
+ rack-protection (2.2.0)
63
63
  rack
64
- rainbow (3.0.0)
64
+ rainbow (3.1.1)
65
65
  rake (13.0.6)
66
- redis (4.5.1)
67
- redis-namespace (1.8.1)
66
+ redis (4.6.0)
67
+ redis-namespace (1.8.2)
68
68
  redis (>= 3.0.4)
69
- regexp_parser (2.2.0)
70
- resque (2.2.0)
69
+ regexp_parser (2.5.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.10.0)
78
- rspec-core (~> 3.10.0)
79
- rspec-expectations (~> 3.10.0)
80
- rspec-mocks (~> 3.10.0)
81
- rspec-core (3.10.1)
82
- rspec-support (~> 3.10.0)
83
- rspec-expectations (3.10.1)
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.10.0)
86
- rspec-mocks (3.10.2)
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.10.0)
89
- rspec-support (3.10.3)
90
- rubocop (1.24.1)
87
+ rspec-support (~> 3.11.0)
88
+ rspec-support (3.11.0)
89
+ rubocop (1.30.1)
91
90
  parallel (~> 1.10)
92
- parser (>= 3.0.0.0)
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.15.1, < 2.0)
94
+ rexml (>= 3.2.5, < 4.0)
95
+ rubocop-ast (>= 1.18.0, < 2.0)
97
96
  ruby-progressbar (~> 1.7)
98
97
  unicode-display_width (>= 1.4.0, < 3.0)
99
- rubocop-ast (1.15.1)
100
- parser (>= 3.0.1.1)
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.7.0)
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,22 +108,21 @@ 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.3)
113
- sinatra (2.1.0)
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.1.0)
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
- yard (0.9.27)
120
+ yard (0.9.28)
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
128
  bundler (~> 2.3)
@@ -138,4 +136,4 @@ DEPENDENCIES
138
136
  yard (~> 0.9, >= 0.9.27)
139
137
 
140
138
  BUNDLED WITH
141
- 2.3.4
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 [Travis CI](https://www.travis-ci.com/) for CI. Most of this is built-in and will work out-of-the-box for GitHub PRs.
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/bin/console CHANGED
@@ -2,7 +2,12 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
- require "waylon"
5
+ require "waylon/core"
6
+ require "waylon/skills/default"
7
+ require "waylon/skills/diagnostics"
8
+ require "waylon/skills/fun"
9
+ require "waylon/skills/groups"
10
+ require "waylon/skills/help"
6
11
 
7
12
  # You can add fixtures and/or initialization code here to make experimenting
8
13
  # with your gem easier. You can also use a different console, if you like.
@@ -46,7 +46,7 @@ module Waylon
46
46
  @namespace || name.to_s.split("::").last.downcase
47
47
  end
48
48
 
49
- # Creates namespaced configuration keys for Webhook subclasses
49
+ # Creates namespaced configuration keys for BaseComponent subclasses
50
50
  # @param (see Config#add_schema)
51
51
  def config(key, default: nil, required: false, type: String)
52
52
  conf = Config.instance
@@ -66,7 +66,10 @@ module Waylon
66
66
  # @param message [Waylon::Message] The received message
67
67
  # @return [Boolean]
68
68
  def properly_mentions?(message)
69
- (mention_only? && message.to_bot?) || (!mention_only? && !message.to_bot?)
69
+ return true unless mention_only?
70
+
71
+ message.to_bot?
72
+ # (mention_only? && message.to_bot?) || (!mention_only? && !message.to_bot?)
70
73
  end
71
74
 
72
75
  # Tokens is used to provide details about the message input to the action
@@ -18,6 +18,9 @@ module Waylon
18
18
  @mechanism.match(input).to_a[1..]
19
19
  end
20
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
21
24
  def named_tokens(input)
22
25
  match_data = @mechanism.match(input)
23
26
  match_data.names.to_h { |n| [n.to_sym, match_data[n]] }
data/lib/waylon/config.rb CHANGED
@@ -41,7 +41,7 @@ module Waylon
41
41
  ENV.keys.grep(/CONF_/).each do |env_key|
42
42
  conf_key = env_key.downcase.split("_")[1..].join(".")
43
43
  ::Waylon::Logger.log("Attempting to set #{conf_key} from #{env_key}", :debug)
44
- self[conf_key] = ENV[env_key]
44
+ self[conf_key] = ENV.fetch(env_key, nil)
45
45
  end
46
46
  true
47
47
  end
data/lib/waylon/core.rb CHANGED
@@ -49,3 +49,4 @@ require "waylon/routes/black_hole"
49
49
  require "waylon/routes/default"
50
50
  require "waylon/routes/permission_denied"
51
51
  require "waylon/webhook"
52
+ require "waylon/webhook_registry"
data/lib/waylon/logger.rb CHANGED
@@ -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
- return @logger if @logger
22
+ @logger ||= json_logger
23
+ end
24
+
25
+ def self.logger=(logger)
26
+ @logger = logger
27
+ end
23
28
 
24
- @logger = ::Logger.new($stderr)
25
- @logger.level = level
26
- @logger.progname = "Waylon"
27
- @logger.formatter = proc do |severity, datetime, progname, msg|
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
- @logger
44
+
45
+ a_logger
39
46
  end
40
47
  end
41
48
  end
@@ -30,6 +30,7 @@ module Waylon
30
30
  end
31
31
 
32
32
  def to_bot?
33
+ # private? || mentions_bot?
33
34
  true
34
35
  end
35
36
  end
@@ -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.process(msg_details(body, from, privately))
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["USER_EMAIL"] && name == "homer.simpson"
151
- ENV["USER_EMAIL"]
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
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Waylon
4
+ module Services
5
+ # A Ping Service for monitoring
6
+ class Ping < Sinatra::Base
7
+ configure do
8
+ set :protection, except: :http_origin
9
+ set :logging, ::Waylon::Logger
10
+ end
11
+
12
+ before do
13
+ content_type "application/json"
14
+ halt 403 unless request.get? || request.options?
15
+ end
16
+
17
+ after do
18
+ headers "Access-Control-Allow-Methods" => %w[OPTIONS GET] if request.options?
19
+ end
20
+
21
+ get "/" do
22
+ { status: :ok }.to_json
23
+ end
24
+
25
+ options "/" do
26
+ halt 200
27
+ end
28
+ end
29
+ end
30
+ end
@@ -27,8 +27,10 @@ module Waylon
27
27
  response << " - *Test Result:* #{state ? "Success" : "Error"}"
28
28
  response << " - *Read time:* #{read_time}s"
29
29
  response << " - *Write time:* #{write_time}s"
30
- response << "*Queue Monitoring:*"
31
- response << " - Failed jobs: #{Resque::Failure.count}"
30
+ if Resque.redis.connected?
31
+ response << "*Queue Monitoring:*"
32
+ response << " - Failed jobs: #{Resque::Failure.count}"
33
+ end
32
34
 
33
35
  reply response.join("\n")
34
36
  end
@@ -146,7 +146,13 @@ module Waylon
146
146
  private
147
147
 
148
148
  def all_group_keys
149
- db.adapter.backend.keys("groups.*")
149
+ if db.adapter.instance_of?(Moneta::Adapters::Redis)
150
+ db.adapter.backend.keys("groups.*")
151
+ else
152
+ groups = []
153
+ db.each_key { |key| groups << key if key.start_with?("groups.") }
154
+ groups
155
+ end
150
156
  end
151
157
 
152
158
  def found_user(user_string)
@@ -6,7 +6,7 @@ module Waylon
6
6
  VERSION = [
7
7
  0, # Major
8
8
  1, # Minor
9
- 2 # Patch
9
+ 5 # Patch
10
10
  ].join(".")
11
11
  end
12
12
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Waylon
4
+ # Registry of Webhook subclasses known to Waylon
5
+ class WebhookRegistry
6
+ include Singleton
7
+
8
+ attr_reader :webhooks
9
+
10
+ # A convenience wrapper around the singleton instance #register method
11
+ # @param (see #register)
12
+ # @return (see #register)
13
+ def self.register(name, class_name)
14
+ instance.register(name, class_name)
15
+ end
16
+
17
+ # Add the provided Webhook class to the registry under `name`
18
+ # @param name [String] The name of the Webhook in the registry
19
+ # @param class_name [Class] The Webhook subclass to add
20
+ # @return [Class] The Webhook subclass
21
+ def register(name, class_name)
22
+ @webhooks ||= {}
23
+ @webhooks[name.to_s] = class_name
24
+ end
25
+
26
+ # Provides a Hash version of this registry
27
+ # @return [Hash]
28
+ def to_hash
29
+ (@webhooks || {}).transform_keys { |k| "/hooks/#{k}" }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ gem install bundler -v '~> 2.3'
4
+ bundle install
5
+ rm -rf pkg/*.gem
6
+ bundle exec rake build
7
+ bundle exec gem push pkg/*.gem
data/scripts/test.sh CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/bin/sh
2
2
 
3
- gem install bundler -v '~> 2.2'
3
+ gem install bundler -v '~> 2.3'
4
4
  bundle install
5
5
  bundle exec rake
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waylon-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-29 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -246,7 +246,6 @@ files:
246
246
  - Rakefile
247
247
  - bin/console
248
248
  - bin/setup
249
- - lib/waylon.rb
250
249
  - lib/waylon/base_component.rb
251
250
  - lib/waylon/condition.rb
252
251
  - lib/waylon/conditions/black_hole.rb
@@ -276,6 +275,7 @@ files:
276
275
  - lib/waylon/rspec/test_worker.rb
277
276
  - lib/waylon/sense.rb
278
277
  - lib/waylon/sense_registry.rb
278
+ - lib/waylon/services/ping.rb
279
279
  - lib/waylon/skill.rb
280
280
  - lib/waylon/skill_registry.rb
281
281
  - lib/waylon/skills/default.rb
@@ -286,6 +286,8 @@ files:
286
286
  - lib/waylon/user.rb
287
287
  - lib/waylon/version.rb
288
288
  - lib/waylon/webhook.rb
289
+ - lib/waylon/webhook_registry.rb
290
+ - scripts/release.sh
289
291
  - scripts/test.sh
290
292
  - waylon-core.gemspec
291
293
  homepage: https://github.com/jgnagy/waylon-core
@@ -295,7 +297,7 @@ metadata:
295
297
  homepage_uri: https://github.com/jgnagy/waylon-core
296
298
  source_code_uri: https://github.com/jgnagy/waylon-core
297
299
  changelog_uri: https://github.com/jgnagy/waylon-core/blob/main/CHANGELOG.md
298
- post_install_message:
300
+ post_install_message:
299
301
  rdoc_options: []
300
302
  require_paths:
301
303
  - lib
@@ -310,8 +312,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
310
312
  - !ruby/object:Gem::Version
311
313
  version: '0'
312
314
  requirements: []
313
- rubygems_version: 3.3.3
314
- signing_key:
315
+ rubygems_version: 3.3.7
316
+ signing_key:
315
317
  specification_version: 4
316
318
  summary: Core library for the Waylon bot framework
317
319
  test_files: []
data/lib/waylon.rb DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "waylon/core"
4
- require "waylon/skills/default"
5
- require "waylon/skills/diagnostics"
6
- require "waylon/skills/fun"
7
- require "waylon/skills/groups"
8
- require "waylon/skills/help"