slack-ruby-socket-mode-bot 0.2.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 470310d522c4279f2b411c8dd08e16793b20f71aa6d6cf28323b142536c1e7a9
4
- data.tar.gz: e1c8cf2889df5e4696abee7753a7d509a9be9c49c112c65d53f1ddcdc279e997
3
+ metadata.gz: c82746d24d6ce1145a79181fbd55e16c5122fa4a00adb0fa7e13cbc736392796
4
+ data.tar.gz: 8134230737396a275d33728ac69a66a6db7fb1e959d3eaa61b62baaed14aa34f
5
5
  SHA512:
6
- metadata.gz: 5d302aee509b8bb504f7d0fcb66b22ca7fa32a87a6e8f042fa2415bcfcafbdc62bc5a101abb1dbfd2d6f3e2cd679bb2c80f6c0a629a402e5bcbf7c568ec5f74b
7
- data.tar.gz: d8ff079d6d9f3203dffd886042cd19b282b923904c63473331f28c3963a8e0665d0ffcf885ad9a9367ab687116ce43502e9d9917d3ff605b94fc6c0c9e488bc2
6
+ metadata.gz: 403cd9978833e1b58bcf40eaa4dc56390be22575db99b55a8b59e18b685e4ca8a4d51d8deae315c2f9933d5d72cab378630305566bb1f3f8d8a563b299d688d9
7
+ data.tar.gz: 99bdea02c873e9b0560936f4519a8d10b6715762016b957ed1a38d39a1ffcb3c9b7f8dda8a04f168164d1a73683793c69f0afce30cb78272b6bce6ff88cc3c7e
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 3.2
3
+ NewCops: enable
3
4
 
4
5
  Style/StringLiterals:
5
6
  EnforcedStyle: double_quotes
@@ -9,4 +10,9 @@ Style/StringLiteralsInInterpolation:
9
10
 
10
11
  Naming/FileName:
11
12
  Exclude:
12
- - 'lib/slack-ruby-socket-mode-bot.rb'
13
+ - "lib/slack-ruby-socket-mode-bot.rb"
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "spec/**/*"
18
+ - "*.gemspec"
data/lib/bot/bot.rb CHANGED
@@ -9,17 +9,18 @@ module SlackSocketModeBot
9
9
  def initialize(bot_token:, app_token:, logger: nil)
10
10
  @bot_token = bot_token
11
11
  @logger = logger || Logger.new($stdout)
12
+ @handlers = []
12
13
 
13
14
  slack_web_client # init
14
15
 
15
16
  @socket_mode_client = Transport::SocketModeClient.new(
16
- app_token:, logger:, callback: method(:process_event)
17
+ app_token:, logger: @logger, callback: method(:process_event)
17
18
  )
18
19
  end
19
20
 
20
21
  # Registers a callback for a matching regex
21
22
  def on(match_regex, &block)
22
- (@handlers ||= []) << MentionHandler.new(match_regex, block)
23
+ @handlers << MentionHandler.new(match_regex, block)
23
24
  end
24
25
 
25
26
  def run!
@@ -29,15 +30,17 @@ module SlackSocketModeBot
29
30
  private
30
31
 
31
32
  def slack_web_client
32
- client = Slack::Web::Client.new(token: @bot_token)
33
- auth_response = client.auth_test
33
+ @slack_web_client ||= begin
34
+ client = Slack::Web::Client.new(token: @bot_token)
35
+ auth_response = client.auth_test
34
36
 
35
- raise auth_response unless auth_response[:ok]
37
+ raise auth_response unless auth_response[:ok]
36
38
 
37
- @bot_user_id = auth_response[:user_id]
38
- @team_id = auth_response[:team_id]
39
+ @bot_user_id = auth_response[:user_id]
40
+ @team_id = auth_response[:team_id]
39
41
 
40
- @slack_web_client ||= client
42
+ client
43
+ end
41
44
  end
42
45
 
43
46
  def handle_error(err)
@@ -60,10 +63,10 @@ module SlackSocketModeBot
60
63
 
61
64
  def payload_processable?(payload)
62
65
  if payload[:team_id] != @team_id
63
- raise UnrecognisedWorkspace.new, "Unrecognised team id #{payload[:team_id]} (expected #{@team_id})"
66
+ raise Errors::UnrecognisedWorkspace, "Unrecognised team id #{payload[:team_id]} (expected #{@team_id})"
64
67
  end
65
68
 
66
- payload[:event][:type] == "app_mention"
69
+ payload.dig(:event, :type) == "app_mention"
67
70
  end
68
71
 
69
72
  def process_handler(handler, text, event)
@@ -22,20 +22,21 @@ module SlackSocketModeBot
22
22
 
23
23
  raise response unless response[:ok]
24
24
 
25
- response[:url]
26
- # debug only:
27
- "#{response[:url]}&debug_reconnects=true"
25
+ if ENV.fetch("ENVIRONMENT", "production").casecmp?("development")
26
+ "#{response[:url]}&debug_reconnects=true"
27
+ else
28
+ response[:url]
29
+ end
28
30
  end
29
31
 
30
- def callback(*args)
31
- @callback.call(*args)
32
+ def callback(*)
33
+ @callback.call(*)
32
34
  end
33
35
 
34
36
  private
35
37
 
36
38
  def slack_web_client
37
- client = Slack::Web::Client.new(token: @app_token)
38
- @slack_web_client ||= client
39
+ @slack_web_client ||= Slack::Web::Client.new(token: @app_token)
39
40
  end
40
41
  end
41
42
  end
@@ -77,10 +77,12 @@ module SlackSocketModeBot
77
77
  end
78
78
 
79
79
  def restart!
80
- @ping_task&.stop
81
80
  @ping_id = 1
82
-
83
81
  @restart.signal
82
+
83
+ # Must come after the signal: stopping @ping_task from within itself
84
+ # (ping! failure) raises Async::Stop, skipping the rest of the method
85
+ @ping_task&.stop
84
86
  end
85
87
 
86
88
  def ping!(connection)
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SlackSocketModeBot
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/mise.lock ADDED
@@ -0,0 +1,48 @@
1
+ # @generated - this file is auto-generated by `mise lock` https://mise.jdx.dev/dev-tools/mise-lock.html
2
+
3
+ [[tools.ruby]]
4
+ version = "4.0.6"
5
+ backend = "core:ruby"
6
+
7
+ [tools.ruby.options]
8
+ compile = "false"
9
+ precompiled_url = "jdx/ruby"
10
+ ruby_build_repo = "https://github.com/rbenv/ruby-build.git"
11
+ ruby_install = "false"
12
+
13
+ [tools.ruby."platforms.linux-arm64"]
14
+ checksum = "sha256:6144c26cd5a1ff85358beb7e68e592ada6d0319aa8093cf353465d60f10aa970"
15
+ url = "https://github.com/jdx/ruby/releases/download/4.0.6-1/ruby-4.0.6.arm64_linux.tar.gz"
16
+ provenance = "github-attestations"
17
+
18
+ [tools.ruby."platforms.linux-arm64-musl"]
19
+ checksum = "sha256:6144c26cd5a1ff85358beb7e68e592ada6d0319aa8093cf353465d60f10aa970"
20
+ url = "https://github.com/jdx/ruby/releases/download/4.0.6-1/ruby-4.0.6.arm64_linux.tar.gz"
21
+ provenance = "github-attestations"
22
+
23
+ [tools.ruby."platforms.linux-x64"]
24
+ checksum = "sha256:aefa111873bac3b15c5c416bfaaca84e793d5312d4496d651ad79c44521b200a"
25
+ url = "https://github.com/jdx/ruby/releases/download/4.0.6-1/ruby-4.0.6.x86_64_linux.tar.gz"
26
+ provenance = "github-attestations"
27
+
28
+ [tools.ruby."platforms.linux-x64-musl"]
29
+ checksum = "sha256:aefa111873bac3b15c5c416bfaaca84e793d5312d4496d651ad79c44521b200a"
30
+ url = "https://github.com/jdx/ruby/releases/download/4.0.6-1/ruby-4.0.6.x86_64_linux.tar.gz"
31
+ provenance = "github-attestations"
32
+
33
+ [tools.ruby."platforms.macos-arm64"]
34
+ checksum = "sha256:518c5849d7ab337790943963ded4f0b402d2d4ededea265288a5a19d4c8fee18"
35
+ url = "https://github.com/jdx/ruby/releases/download/4.0.6-1/ruby-4.0.6.macos.tar.gz"
36
+ provenance = "github-attestations"
37
+
38
+ [tools.ruby."platforms.macos-x64"]
39
+ checksum = "sha256:837d299e8f7ddf2be31a229a7a7e019d354979825117989acb3b32b1a9be262a"
40
+ url = "https://cache.ruby-lang.org/pub/ruby/4.0/ruby-4.0.6.tar.gz"
41
+
42
+ [[tools.ruby]]
43
+ version = "4.0.6"
44
+ backend = "core:ruby"
45
+
46
+ [tools.ruby."platforms.windows-x64"]
47
+ checksum = "sha256:328d7a86bea2f4c432783025050c9ffa1c36fcfc54ebccc466b63450ec3af223"
48
+ url = "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-4.0.6-1/rubyinstaller-4.0.6-1-x64.7z"
data/mise.toml ADDED
@@ -0,0 +1,11 @@
1
+ [tools]
2
+ ruby = "latest"
3
+
4
+ [tasks.test]
5
+ run = "bundle exec rake"
6
+
7
+ [tasks.check]
8
+ run = "bundle exec rubocop"
9
+
10
+ [deps.bundler]
11
+ auto = true
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-socket-mode-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - guille
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: async
@@ -89,13 +88,15 @@ files:
89
88
  - lib/transport/socket_mode_client.rb
90
89
  - lib/transport/websocket.rb
91
90
  - lib/version.rb
91
+ - mise.lock
92
+ - mise.toml
92
93
  homepage: https://github.com/guille/slack-socket-mode-bot
93
94
  licenses:
94
95
  - MIT
95
96
  metadata:
96
97
  homepage_uri: https://github.com/guille/slack-socket-mode-bot
97
98
  source_code_uri: https://github.com/guille/slack-socket-mode-bot
98
- post_install_message:
99
+ rubygems_mfa_required: 'true'
99
100
  rdoc_options: []
100
101
  require_paths:
101
102
  - lib
@@ -110,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubygems_version: 3.5.3
114
- signing_key:
114
+ rubygems_version: 4.0.16
115
115
  specification_version: 4
116
116
  summary: Gem for implementing simple bots for Slack using Socket Mode
117
117
  test_files: []