Skip to content

Commit

Permalink
add bot to channel when sending a reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Sep 27, 2024
1 parent 6d5c288 commit 27c119e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
14 changes: 7 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-08-11 22:31:55 UTC using RuboCop version 1.34.1.
# on 2024-09-27 17:34:39 UTC using RuboCop version 1.45.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 47

# Offense count: 3
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
# Offense count: 6
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 12
Max: 13

# Offense count: 1
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Expand All @@ -24,7 +24,7 @@ Metrics/ParameterLists:

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 122
6 changes: 4 additions & 2 deletions app/services/admin/actions/replay_flow.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
module Actions
class ReplayFlow < RailsAdmin::Config::Actions::Base
Expand All @@ -22,7 +24,7 @@ class ReplayFlow < RailsAdmin::Config::Actions::Base

register_instance_option :controller do
proc do
flash[:success] = "We're replaying this flow right now!"
flash[:success] = t('admin.actions.replay_flow.message')
if Rails.env.production?
HardWorker.perform_async(@object.id)
else
Expand All @@ -34,4 +36,4 @@ class ReplayFlow < RailsAdmin::Config::Actions::Base
end
end
end
end
end
6 changes: 0 additions & 6 deletions app/services/clients/slack/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ def list
channels.map { |channel| channel.slice(:id, :name).to_h }.sort_by { |hash| hash['name'] }
end

def join!(channel)
client.conversations_join({
channel:
})
end

def remove_hash(channel)
channel.gsub('#', '')
end
Expand Down
8 changes: 8 additions & 0 deletions app/services/clients/slack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def client

@client = ::Slack::Web::Client.new
end

private

def join!(channel)
client.conversations_join({
channel:
})
end
end
end
end
19 changes: 11 additions & 8 deletions app/services/clients/slack/reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ module Clients
module Slack
class Reaction < Client
def send!(channel, reaction, timestamp)
# @TODO: remove this cleaning from this method
return unless timestamp

channel = remove_hash(channel) if channel.upcase == channel

clean_reactions!(channel, timestamp)

client.reactions_add(
channel:,
name: reaction,
timestamp:
)
begin
clean_reactions!(channel, timestamp)
client.reactions_add(
channel:,
name: reaction,
timestamp:
)
rescue ::Slack::Web::Api::Errors::NotInChannel
join!(channel)
send!(channel, reaction, timestamp)
end
end

private
Expand Down
1 change: 0 additions & 1 deletion config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
show_in_app
replay_flow


## With an audit adapter, you can add:
# history_index
# history_show
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ en:
actions:
replay_flow:
menu: "Rerun flow"
message: "We're replaying this flow right now!"

0 comments on commit 27c119e

Please sign in to comment.