kfei / slack-cleaner

:speech_balloon: Bulk delete messages and files on Slack
MIT License
1.24k stars 144 forks source link

Request: Delete messages older than X #27

Open briangig opened 8 years ago

briangig commented 8 years ago

I'm sure there is a way to do this with a variable...but I am too dumb. Would be a great feature to have built in!

Example: Delete messages older than one week, 3 days etc.

jonayreyes commented 7 years ago

What about date+time for the --before parameter? or even a --after too

briangig commented 7 years ago

If anyone ever wants to do this, run the slack-cleaner commant in a PowerShell script:

$Week = (get-date (Get-Date).AddDays(-5) -Format "yyyyMMdd")

Where -5 is the number of days back you want to clean up.

then

--before $Week

thezoggy commented 7 years ago

bash script for those that care.. just change variable for your name/token/how many days.

delete attachments, delete direct messages to a specific user, delete messages to a specific channel

#!/bin/bash
DAYS=12
USER=slack-username
TOKEN=xoxp-insert-your-token
RATE=1
dated=`date -j -v-${DAYS}d +%Y%m%d`

printf "\nRemoving files older than $DAYS days ($dated)\n"
slack-cleaner --rate $RATE --token $TOKEN --file --user $USER --perform --before $dated

printf "\nRemoving messages older than $DAYS days to Chase\n"                                                                                                                                                                                                                             
slack-cleaner --rate $RATE --token $TOKEN --message --direct chase --user $USER --perform --before $dated

printf "\nRemoving messages older than $DAYS days to #random\n"
slack-cleaner --rate $RATE --token $TOKEN --message --channel random  --user $USER --perform --before $dated