Skip to content

Commit

Permalink
Merge pull request #26 from RodrigoMNardi/feature/translatename2id
Browse files Browse the repository at this point in the history
Translate Username to ID
  • Loading branch information
RodrigoMNardi authored Oct 14, 2024
2 parents 3de1cee + f51befb commit 87ef450
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/github_app/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class Server < Sinatra::Base
halt 200
end

get '/translate/:name' do
user_info = Client.new.find_user_id_by_name(params[:name])

halt 404, 'User not found' unless user_info

halt 200, user_info.profile.display_name
end

post '/comment' do
halt 401, 'Invalid user / password' unless authentication
Client.new.chat(request.body.read)
Expand Down
9 changes: 8 additions & 1 deletion lib/slack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ def initialize
config.open_timeout = 60
end

@client = Slack::Web::Client.new
@client = Slack::Web::Client.new do |faraday|
faraday.ssl[:ca_file] = '/home/rnardi/.rvm/gems/ruby-3.3.1@slack_bot/gems/certified-1.0.0/ca-certificates.crt'
end
end

def find_user_id_by_name(username)
user = @client.users_info(user: "@#{username}")
user ? user.id : nil

Check warning on line 30 in lib/slack/client.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use safe navigation (`&.`) instead of checking if an object exists before calling the method. Raw Output: lib/slack/client.rb:30:5: C: Style/SafeNavigation: Use safe navigation (`&.`) instead of checking if an object exists before calling the method.
end

def chat(message, channel: fetch_channel)
Expand Down

0 comments on commit 87ef450

Please sign in to comment.