Skip to content
Open
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
15 changes: 13 additions & 2 deletions bin/slackcat
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Slackcat
@channels ||= get_objects('channels.list', 'channels')
end

def channel_by(name)
channels().find { |channel| channel['name'] == name }
end

def groups
@groups ||= get_objects('groups.list', 'groups')
end
Expand Down Expand Up @@ -114,8 +118,15 @@ if opts.values_at(:channels, :groups, :users).all?(&:empty?)
end

## translate destination names into slack ids
channels = opts[:channels].split(/[\s,]+/).map do |name|
slack.channels.find { |channel| channel['name'] == name }.fetch('id')
individual_channel_names = opts[:channels].split(/[\s,]+/)
existing_channel_names = individual_channel_names.select {|name| slack.channel_by(name)}

(individual_channel_names - existing_channel_names).each do |name|
puts "skipping channel #{name}: not available (maybe use -g for group?)"
end

channels = existing_channel_names.map do |name|
slack.channel_by(name).fetch('id')
end

groups = opts[:groups].split(/[\s,]+/).map do |name|
Expand Down