Code Monkey home page Code Monkey logo

slack-cleaner's Introduction

slack-cleaner

Bulk delete messages and files on Slack.

this is a fork of https://github.com/kfei/slack-cleaner

Install

Install from Pip:

pip install -e git+https://github.com/dandes3/slack-cleaner.git#egg=slack-cleaner

Arguments

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)
  --log                Create a log file in the current directory
  --quiet              Run quietly, does not log messages deleted
  --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
  --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 with specified pattern (regex)
  --perform            Perform the task

Minimal Slack permission scopes required

  • channels:history
  • channels:read
  • chat:write:bot
  • users:read

Usage

# 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

# TODO add pattern example, add keep_pinned example, add quiet

# Always have a look at help message
slack-cleaner --help

Tokens

You will need to generate a Slack legacy token to use slack-cleaner. You can generate a token here:

https://api.slack.com/custom-integrations/legacy-tokens

Tips

After the task, a backup file slack-cleaner.<timestamp>.log will be created in current directory if --log is supplied.

If any API problem occurred, try --rate=<delay-in-seconds> to reduce the API call rate (which by default is unlimited).

If you see the following warning from urllib3, consider to install missing packages: pip install --upgrade requests[security] or just upgrade your Python to 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.

Credits

To all the people who can only afford a free plan. ๐Ÿ˜ข

slack-cleaner's People

Contributors

sgratzl avatar kfei avatar dandes3 avatar thebestmensch avatar jomasti avatar puzzlement avatar renshuki avatar grantholly avatar jamessa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.