Last active
October 3, 2016 15:49
-
-
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)
This file contains hidden or 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
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}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get the token from here: https://api.slack.com/docs/oauth-test-tokens