Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate Username to ID #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
Loading