Created
April 1, 2020 08:50
-
-
Save aboritskiy/b5ec8f0376e16b489fc2b4387cd30364 to your computer and use it in GitHub Desktop.
archives dead slack channels
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
TOKEN="" | |
curl "https://slack.com/api/channels.list?token=$TOKEN&exclude_archived=true&pretty=1" > /tmp/channels.list | |
IDS=$(cat /tmp/channels.list | jq '.channels[] | select(.num_members == 0) | .id' | sed -e 's/"//g') | |
for ID in $IDS; do | |
CHANNEL_DATA=$(cat /tmp/channels.list | jq ".channels[] | select(.id == \"$ID\") | \"\(.id) \(.name) \(.num_members)\"") | |
echo "$CHANNEL_DATA" | |
read -p " proceed? " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo " archiving..." | |
URL="https://slack.com/api/channels.archive?token=$TOKEN&channel=$ID&pretty=1" | |
echo $URL | |
curl "$URL" | |
fi | |
done | |
IDS=$(cat /tmp/channels.list | jq '.channels[] | select(.members == []) | .id' | sed -e 's/"//g') | |
for ID in $IDS; do | |
CHANNEL_DATA=$(cat /tmp/channels.list | jq ".channels[] | select(.id == \"$ID\") | \"\(.id) \(.name) \(.num_members)\"") | |
echo "$CHANNEL_DATA" | |
read -p " proceed? " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo " archiving..." | |
URL="https://slack.com/api/channels.archive?token=$TOKEN&channel=$ID&pretty=1" | |
echo $URL | |
curl "$URL" | |
fi | |
done | |
IDS=$(cat /tmp/channels.list | jq '.channels[] | select(.name | contains("incident")) | .id' | sed -e 's/"//g') | |
for ID in $IDS; do | |
CHANNEL_DATA=$(cat /tmp/channels.list | jq ".channels[] | select(.id == \"$ID\") | \"\(.id) \(.name) \(.num_members)\"") | |
echo "$CHANNEL_DATA" | |
read -p " proceed? " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo " archiving..." | |
URL="https://slack.com/api/channels.archive?token=$TOKEN&channel=$ID&pretty=1" | |
echo $URL | |
curl "$URL" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment