大量刪除 Slack 上的消息和檔案。
這是 https://github.com/kfei/slack-cleaner 的分支
基於 Python 模組的改進版本位於 https://github.com/sgratzl/slack_cleaner2
從 Pip 安裝:
pip install slack-cleaner
目前開發版本:
pip install -e git+https://github.com/sgratzl/slack-cleaner.git#egg=slack-cleaner
如果您更喜歡 Docker,還有一個預先建置的 Docker 映像:
docker pull sgratzl/slack-cleaner
只要對每個指令使用docker run -it --rm sgratzl/slack-cleaner -c "slack-cleaner ..."
或使用docker run -it --rm sgratzl/slack-cleaner
跳到 shell。
安裝 Fedora 或 EPEL7
@rapgro 維護 Fedora 和 EPEL7 的軟體包
# Fedora
dnf install slack-cleaner
# EPEL7
yum install -y epel-release ; yum install slack-cleaner
usage: slack-cleaner [-h] --token TOKEN [--log] [--quiet] [--rate RATE]
[--as_user] [--message | --file | --info] [--regex]
[--channel CHANNEL] [--direct DIRECT] [--group GROUP]
[--mpdirect MPDIRECT] [--user USER] [--botname BOTNAME]
[--bot] [--keeppinned] [--after AFTER] [--before BEFORE]
[--types TYPES] [--pattern PATTERN] [--perform]
optional arguments:
-h, --help show this help message and exit
--token TOKEN Slack API token (https://api.slack.com/web) or SLACK_TOKEN env var
--log Create a log file in the current directory
--quiet Run quietly, does not log messages deleted
--proxy Proxy Server url:port
--verify Verify option for Session (http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification)
--rate RATE Delay between API calls (in seconds)
--as_user Pass true to delete the message as the authed user. Bot
users in this context are considered authed users.
--message Delete messages
--file Delete files
--info Show information
--regex Interpret channel, direct, group, and mpdirect as regex
--channel CHANNEL Channel name's, e.g., general
--direct DIRECT Direct message's name, e.g., sherry
--group GROUP Private group's name
--mpdirect MPDIRECT Multiparty direct message's name, e.g.,
sherry,james,johndoe
--user USER Delete messages/files from certain user
--botname BOTNAME Delete messages/files from certain bots. Implies '--bot'
--bot Delete messages from bots
--keeppinned exclude pinned messages from deletion
--after AFTER Delete messages/files newer than this time (YYYYMMDD)
--before BEFORE Delete messages/files older than this time (YYYYMMDD)
--types TYPES Delete files of a certain type, e.g., posts,pdfs
--pattern PATTERN Delete messages/files with specified pattern or if one of their attachments matches (regex)
--perform Perform the task
授予的權限取決於您要使用該腳本的用途。根據您的使用情況授予以下權限。
除了授予權限之外,如果您希望使用此腳本刪除其他人發布的消息或文件,您將需要成為工作區的所有者或管理員。
channels:history
channels:read
chat:write
(或對於舊應用程式同時使用chat:write:user
和chat:write:bot
)users:read
groups:history
groups:read
chat:write
(或chat:write:user
)users:read
im:history
im:read
chat:write
(或chat:write:user
)users:read
mpim:history
mpim:read
chat:write
(或chat:write:user
)users:read
files:read
files:write
(或files:write:user
)users:read
# Delete all messages from a channel
slack-cleaner --token < TOKEN > --message --channel general --user " * "
# Delete all messages from a private group aka private channel
slack-cleaner --token < TOKEN > --message --group hr --user " * "
# Delete all messages from a direct message channel
slack-cleaner --token < TOKEN > --message --direct sherry --user johndoe
# Delete all messages from a multiparty direct message channel. Note that the
# list of usernames must contains yourself
slack-cleaner --token < TOKEN > --message --mpdirect sherry,james,johndoe --user " * "
# Delete all messages from certain user
slack-cleaner --token < TOKEN > --message --channel gossip --user johndoe
# Delete all messages from bots (especially flooding CI updates)
slack-cleaner --token < TOKEN > --message --channel auto-build --bot
# Delete all messages older than 2015/09/19
slack-cleaner --token < TOKEN > --message --channel general --user " * " --before 20150919
# Delete all files
slack-cleaner --token < TOKEN > --file --user " * "
# Delete all files from certain user
slack-cleaner --token < TOKEN > --file --user johndoe
# Delete all snippets and images
slack-cleaner --token < TOKEN > --file --types snippets,images
# Show information about users, channels:
slack-cleaner --token < TOKEN > --info
# Delete matching a regexp pattern
slack-cleaner --token < TOKEN > --pattern " (bar|foo.+) "
# TODO add add keep_pinned example, add quiet
# Always have a look at help message
slack-cleaner --help
清理器需要您授予 Slack 的 API 權限,讓它執行它所需的操作。您可以透過在要使用它的工作區中將其註冊為應用程式來授予這些權限。
您可以透過以下方式向應用程式授予這些權限:
--token
參數任務完成後,如果提供--log
,將在目前目錄中建立備份檔案slack-cleaner.<timestamp>.log
。
如果出現任何 API 問題,請嘗試--rate=<delay-in-seconds>
降低 API 呼叫速率(預設是無限的)。
如果您從urllib3
看到以下警告,請考慮安裝缺少的軟體包: pip install --upgrade requests[security]
或將 Python 升級到 2.7.9。
InsecurePlatformWarning: A true SSLContext object is not available.
This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.
For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
致所有隻能負擔免費方案的人。 ?