-
-
Save eduardopintor/1a022c58ac1dd42212633293a6166945 to your computer and use it in GitHub Desktop.
Script to delete old files from Slack
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
#!/usr/bin/env php | |
<?php | |
date_default_timezone_set('GMT'); | |
if (count($argv)<2) { | |
echo $argv[0] . ' <token> <until>' . PHP_EOL; | |
echo 'Example: ' . $argv[0] . ' abcd-12345678-123456789-12345 \'-3 months\'' . PHP_EOL; | |
exit; | |
} | |
$token = $argv[1]; | |
$timestamp = isset($argv[2]) ? strtotime($argv[2]) : null; | |
function slack($function, $options = []) { | |
global $token; | |
$response = file_get_contents('https://slack.com/api/' . $function . '?' . http_build_query(array_merge(['token' => $token],$options))); | |
return json_decode($response, true); | |
} | |
$files = slack('files.list', ['ts_to' => $timestamp]); | |
foreach ($files['files'] as $file) { | |
$response = slack('files.delete', ['file' => $file['id']]); | |
echo 'file ' . $file['id'] . ' deleted: ' . $file['permalink'] . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment