-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f98d6f2
commit 7bb22fd
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'slack-ruby-client' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activesupport (5.1.4) | ||
concurrent-ruby (~> 1.0, >= 1.0.2) | ||
i18n (~> 0.7) | ||
minitest (~> 5.1) | ||
tzinfo (~> 1.1) | ||
concurrent-ruby (1.0.5) | ||
faraday (0.13.1) | ||
multipart-post (>= 1.2, < 3) | ||
faraday_middleware (0.12.2) | ||
faraday (>= 0.7.4, < 1.0) | ||
gli (2.17.1) | ||
hashie (3.5.6) | ||
i18n (0.9.1) | ||
concurrent-ruby (~> 1.0) | ||
minitest (5.10.3) | ||
multipart-post (2.0.0) | ||
slack-ruby-client (0.11.0) | ||
activesupport | ||
faraday (>= 0.9) | ||
faraday_middleware | ||
gli | ||
hashie | ||
websocket-driver | ||
thread_safe (0.3.6) | ||
tzinfo (1.2.4) | ||
thread_safe (~> 0.1) | ||
websocket-driver (0.7.0) | ||
websocket-extensions (>= 0.1.0) | ||
websocket-extensions (0.1.3) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
slack-ruby-client | ||
|
||
BUNDLED WITH | ||
1.15.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'slack-ruby-client' | ||
|
||
Slack.configure do |config| | ||
config.token = ENV['SLACK_API_TOKEN'] | ||
raise 'need to provide a slack token in SLACK_API_TOKEN' unless config.token | ||
end | ||
|
||
raise 'need to specify a channel to invite everyone to' if ARGV.length < 1 | ||
|
||
client = Slack::Web::Client.new | ||
channel = client.channels_list.channels.find do |c| | ||
c.name == ARGV[0] | ||
end | ||
|
||
raise "couldn't find a channel called #{ARGV[0]}" unless channel | ||
|
||
print "inviting everyone to ##{channel.name}, are you sure? (yes or no) " | ||
exit unless $stdin.gets.chomp == 'yes' | ||
|
||
puts "let the games begin!" | ||
puts | ||
|
||
# channels.invite works with up to 30 users at a time | ||
users_to_invite = client.users_list.members.select do |user| | ||
!user.deleted | ||
end | ||
users_to_invite.each_slice(30) do |users| | ||
puts "inviting #{users.map(&:name).join(', ')}" | ||
begin | ||
sleep 2 | ||
client.post('channels.invite', channel: channel.id, users: users.map(&:id).join(',')) | ||
rescue Slack::Web::Api::Errors::SlackError => e | ||
# Ignore errors caused by users we tried to invite already being members. | ||
# Note that Slack will still invite all the others to the channel | ||
unless e.response.body.errors && e.response.body.errors.all? { |error| error.error == 'already_in_channel' } | ||
puts "Oh no! Looks like something went wrong. The response from Slack's API was: #{e.response.inspect}" | ||
exit | ||
end | ||
end | ||
end | ||
|
||
puts | ||
puts "done! #{users_to_invite.length} users were invited." |