Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Last active October 3, 2016 15:49
Show Gist options
  • Save yitsushi/89dd18df21627e680f418d701b7d5ee5 to your computer and use it in GitHub Desktop.
Save yitsushi/89dd18df21627e680f418d701b7d5ee5 to your computer and use it in GitHub Desktop.
set Env TOKEN to your personal (or an admin) token (bot token does not work)
require "slack"
client = Slack::Client.new token: ENV['TOKEN']
LIMIT = 20 # days
from_time = Time.now.to_i - (60 * 60 * 24 * LIMIT)
pages = client.files_list(:types => 'images', ts_to: from_time)['paging']['pages'].to_i
deleted_files_count = 0
cant_delete = 0
while pages > 0 do
files = client.files_list(page: pages, types: 'images', ts_to: from_time)['files']
files.each_with_index do |file, index|
print sprintf('Page %-4d => %10s (%d/%d)', pages, file['id'], index, files.length)
response = client.files_delete(file: file['id'])
deleted_files_count += 1 if response['ok']
cant_delete += 1 if response['error'] == 'cant_delete_file'
print "\r"
end
pages -= 1
end
puts sprintf('%-80s', "Deleted files: #{deleted_files_count}")
puts sprintf('%-80s', "Permission denied: #{cant_delete}")
@yitsushi
Copy link
Author

yitsushi commented Oct 3, 2016

gem install slack-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment