slack-cleaner2


Nameslack-cleaner2 JSON
Version 3.2.7 PyPI version JSON
download
home_pagehttps://github.com/sgratzl/slack_cleaner2
SummarySlack Cleaner2 is an improved slack cleaner version using a python first approach
upload_time2024-06-15 14:59:16
maintainerNone
docs_urlNone
authorSamuel Gratzl
requires_pythonNone
licenseMIT license
keywords slack_cleaner2 slack slack-cleaner
VCS
bugtrack_url
requirements slack_sdk colorama python-dateutil requests
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # slack_cleaner2

[![License: MIT][mit-image]][mit-url] [![Github Actions][github-actions-image]][github-actions-url] [![PyPi][pypi-image]][pypi-url] [![Read the Docs][docs-image]][docs-url]

Bulk delete messages and files on Slack.

## Install

Install from PyPi:

```sh
pip install slack-cleaner2
```

latest version

```sh
pip install -e git+https://github.com/sgratzl/slack_cleaner2.git#egg=slack_cleaner2
```

## Usage

In contrast to the original version (https://github.com/kfei/slack-cleaner) this version is a focusing on pure python package that allows for easy scripting instead of a vast amount of different command line arguments.

basic usage

```python
from slack_cleaner2 import *

s = SlackCleaner('SECRET TOKEN')
# list of users
s.users
# list of all kind of channels
s.conversations

# delete all messages in -bots channels
for msg in s.msgs(filter(match('.*-bots'), s.conversations)):
  # delete messages, its files, and all its replies (thread)
  msg.delete(replies=True, files=True)

# delete all general messages and also iterate over all replies
for msg in s.c.general.msgs(with_replies=True):
  msg.delete()
```

[Migration Guides form slack-cleaner](https://github.com/sgratzl/slack-cleaner/issues/79) contains a series of common pattern in slack cleaner and their counterpart in Slack Cleaner2

## Token

The slack cleaner needs you to give Slack's API permission to let it run the
operations it needs. You grant these by registering it as an app in the
workspace you want to use it in.

You can grant these permissions to the app by:

1. going to [Your Apps](https://api.slack.com/apps)
1. select 'Create New App', fill out an App Name (eg 'Slack Cleaner') and
   select the Slack workspace you want to use it in
1. select 'OAuth & Permissions' in the sidebar
1. scroll down to **User Token Scope** and select all scopes you need according to list below
1. select 'Save changes'
1. select 'Install App to Workspace'
1. review the permissions and press 'Authorize'
1. copy the 'OAuth Access Token' shown, and use as the first argument to `SlackCleaner`

The token should start with **xoxp** and not like bot tokens with **xoxb**.

Beyond granting permissions, if you wish to use this library to delete
messages or files posted by others, you will need to be an [Owner or
Admin](https://get.slack.help/hc/en-us/articles/218124397-Change-a-member-s-role) of the workspace.

### User Token Scopes by Use Case

#### General channel and user detection

-   `users:read`
-   `channels:read`
-   `groups:read`
-   `im:read`
-   `mpim:read`

#### Deleting messages from public channels

-   `users:read`
-   `channels:read`
-   `channels:history`
-   `chat:write`

#### Deleting messages from private channels

-   `users:read`
-   `groups:read`
-   `groups:history`
-   `chat:write`

#### Deleting messages from 1:1 IMs

**Note**: You can only delete your own messages, not the ones of others. This is due to a restriction in the Slack API and there is nothing one can do about it.

-   `im:read`
-   `im:history`
-   `users:read`
-   `chat:write`

#### Deleting messages from multi-person IMs

-   `mpim:read`
-   `mpim:history`
-   `users:read`
-   `chat:write`

#### Deleting files

-   `files:read`
-   `users:read`
-   `files:write`

### All User Token scopes

![user token scopes](https://user-images.githubusercontent.com/4129778/81291893-f20b9580-906a-11ea-80a8-f19f3e6878e9.png)

## Docker

There is no direct docker file available, however since it is a python module one can easily create one:

```
FROM python:3.9-alpine

LABEL maintainer="Samuel Gratzl <sam@sgratzl.com>"

VOLUME "/backup"
WORKDIR /backup

RUN pip --no-cache-dir install slack-cleaner2

CMD ["python", "-"]
```

An Docker image named `slack_cleaner2` with this Dockerfile would be used like

```sh
cat myscript.py | docker run -i slack_cleaner2
```

The `myscript.py` file is a python script using the slack_cleaner2 module.

## Credits

**To all the people who can only afford a free plan. :cry:**

## Development

### Release

```sh
bumpversion patch
git commit -am 'release vX.X.X'
git tag vX.X.X
invoke release
git push
git push --tags
```

change version in `slack_cleaner2/_info.py`

[mit-image]: https://img.shields.io/badge/License-MIT-yellow.svg
[mit-url]: https://opensource.org/licenses/MIT
[github-actions-image]: https://github.com/sgratzl/slack_cleaner2/workflows/python/badge.svg
[github-actions-url]: https://github.com/sgratzl/slack_cleaner2/actions
[pypi-image]: https://img.shields.io/pypi/v/slack_cleaner2
[pypi-url]: https://pypi.python.org/pypi/slack_cleaner2/
[docs-image]: https://readthedocs.org/projects/slack-cleaner2/badge/?version=latest
[docs-url]: https://slack-cleaner2.readthedocs.io/en/latest/?badge=latest

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sgratzl/slack_cleaner2",
    "name": "slack-cleaner2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "slack_cleaner2 slack slack-cleaner",
    "author": "Samuel Gratzl",
    "author_email": "sam@sgratzl.com",
    "download_url": "https://files.pythonhosted.org/packages/3d/52/b6e241fe93d4c0389ef342a55f4108d149b0890e0c16c2d06214b40e8787/slack_cleaner2-3.2.7.tar.gz",
    "platform": null,
    "description": "# slack_cleaner2\r\n\r\n[![License: MIT][mit-image]][mit-url] [![Github Actions][github-actions-image]][github-actions-url] [![PyPi][pypi-image]][pypi-url] [![Read the Docs][docs-image]][docs-url]\r\n\r\nBulk delete messages and files on Slack.\r\n\r\n## Install\r\n\r\nInstall from PyPi:\r\n\r\n```sh\r\npip install slack-cleaner2\r\n```\r\n\r\nlatest version\r\n\r\n```sh\r\npip install -e git+https://github.com/sgratzl/slack_cleaner2.git#egg=slack_cleaner2\r\n```\r\n\r\n## Usage\r\n\r\nIn contrast to the original version (https://github.com/kfei/slack-cleaner) this version is a focusing on pure python package that allows for easy scripting instead of a vast amount of different command line arguments.\r\n\r\nbasic usage\r\n\r\n```python\r\nfrom slack_cleaner2 import *\r\n\r\ns = SlackCleaner('SECRET TOKEN')\r\n# list of users\r\ns.users\r\n# list of all kind of channels\r\ns.conversations\r\n\r\n# delete all messages in -bots channels\r\nfor msg in s.msgs(filter(match('.*-bots'), s.conversations)):\r\n  # delete messages, its files, and all its replies (thread)\r\n  msg.delete(replies=True, files=True)\r\n\r\n# delete all general messages and also iterate over all replies\r\nfor msg in s.c.general.msgs(with_replies=True):\r\n  msg.delete()\r\n```\r\n\r\n[Migration Guides form slack-cleaner](https://github.com/sgratzl/slack-cleaner/issues/79) contains a series of common pattern in slack cleaner and their counterpart in Slack Cleaner2\r\n\r\n## Token\r\n\r\nThe slack cleaner needs you to give Slack's API permission to let it run the\r\noperations it needs. You grant these by registering it as an app in the\r\nworkspace you want to use it in.\r\n\r\nYou can grant these permissions to the app by:\r\n\r\n1. going to [Your Apps](https://api.slack.com/apps)\r\n1. select 'Create New App', fill out an App Name (eg 'Slack Cleaner') and\r\n   select the Slack workspace you want to use it in\r\n1. select 'OAuth & Permissions' in the sidebar\r\n1. scroll down to **User Token Scope** and select all scopes you need according to list below\r\n1. select 'Save changes'\r\n1. select 'Install App to Workspace'\r\n1. review the permissions and press 'Authorize'\r\n1. copy the 'OAuth Access Token' shown, and use as the first argument to `SlackCleaner`\r\n\r\nThe token should start with **xoxp** and not like bot tokens with **xoxb**.\r\n\r\nBeyond granting permissions, if you wish to use this library to delete\r\nmessages or files posted by others, you will need to be an [Owner or\r\nAdmin](https://get.slack.help/hc/en-us/articles/218124397-Change-a-member-s-role) of the workspace.\r\n\r\n### User Token Scopes by Use Case\r\n\r\n#### General channel and user detection\r\n\r\n-   `users:read`\r\n-   `channels:read`\r\n-   `groups:read`\r\n-   `im:read`\r\n-   `mpim:read`\r\n\r\n#### Deleting messages from public channels\r\n\r\n-   `users:read`\r\n-   `channels:read`\r\n-   `channels:history`\r\n-   `chat:write`\r\n\r\n#### Deleting messages from private channels\r\n\r\n-   `users:read`\r\n-   `groups:read`\r\n-   `groups:history`\r\n-   `chat:write`\r\n\r\n#### Deleting messages from 1:1 IMs\r\n\r\n**Note**: You can only delete your own messages, not the ones of others. This is due to a restriction in the Slack API and there is nothing one can do about it.\r\n\r\n-   `im:read`\r\n-   `im:history`\r\n-   `users:read`\r\n-   `chat:write`\r\n\r\n#### Deleting messages from multi-person IMs\r\n\r\n-   `mpim:read`\r\n-   `mpim:history`\r\n-   `users:read`\r\n-   `chat:write`\r\n\r\n#### Deleting files\r\n\r\n-   `files:read`\r\n-   `users:read`\r\n-   `files:write`\r\n\r\n### All User Token scopes\r\n\r\n![user token scopes](https://user-images.githubusercontent.com/4129778/81291893-f20b9580-906a-11ea-80a8-f19f3e6878e9.png)\r\n\r\n## Docker\r\n\r\nThere is no direct docker file available, however since it is a python module one can easily create one:\r\n\r\n```\r\nFROM python:3.9-alpine\r\n\r\nLABEL maintainer=\"Samuel Gratzl <sam@sgratzl.com>\"\r\n\r\nVOLUME \"/backup\"\r\nWORKDIR /backup\r\n\r\nRUN pip --no-cache-dir install slack-cleaner2\r\n\r\nCMD [\"python\", \"-\"]\r\n```\r\n\r\nAn Docker image named `slack_cleaner2` with this Dockerfile would be used like\r\n\r\n```sh\r\ncat myscript.py | docker run -i slack_cleaner2\r\n```\r\n\r\nThe `myscript.py` file is a python script using the slack_cleaner2 module.\r\n\r\n## Credits\r\n\r\n**To all the people who can only afford a free plan. :cry:**\r\n\r\n## Development\r\n\r\n### Release\r\n\r\n```sh\r\nbumpversion patch\r\ngit commit -am 'release vX.X.X'\r\ngit tag vX.X.X\r\ninvoke release\r\ngit push\r\ngit push --tags\r\n```\r\n\r\nchange version in `slack_cleaner2/_info.py`\r\n\r\n[mit-image]: https://img.shields.io/badge/License-MIT-yellow.svg\r\n[mit-url]: https://opensource.org/licenses/MIT\r\n[github-actions-image]: https://github.com/sgratzl/slack_cleaner2/workflows/python/badge.svg\r\n[github-actions-url]: https://github.com/sgratzl/slack_cleaner2/actions\r\n[pypi-image]: https://img.shields.io/pypi/v/slack_cleaner2\r\n[pypi-url]: https://pypi.python.org/pypi/slack_cleaner2/\r\n[docs-image]: https://readthedocs.org/projects/slack-cleaner2/badge/?version=latest\r\n[docs-url]: https://slack-cleaner2.readthedocs.io/en/latest/?badge=latest\r\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Slack Cleaner2 is an improved slack cleaner version using a python first approach",
    "version": "3.2.7",
    "project_urls": {
        "Homepage": "https://github.com/sgratzl/slack_cleaner2"
    },
    "split_keywords": [
        "slack_cleaner2",
        "slack",
        "slack-cleaner"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f90ac6f4d2339962a16568532099eac94ce7c92207b45953615e65c262082bd",
                "md5": "d2802123519b7bc48516544eb95a38dc",
                "sha256": "23684909208454eb5731af1d46c3b335e5de45cb5c5e7e86826c26e030168cd5"
            },
            "downloads": -1,
            "filename": "slack_cleaner2-3.2.7-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d2802123519b7bc48516544eb95a38dc",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 19782,
            "upload_time": "2024-06-15T14:59:15",
            "upload_time_iso_8601": "2024-06-15T14:59:15.139073Z",
            "url": "https://files.pythonhosted.org/packages/0f/90/ac6f4d2339962a16568532099eac94ce7c92207b45953615e65c262082bd/slack_cleaner2-3.2.7-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3d52b6e241fe93d4c0389ef342a55f4108d149b0890e0c16c2d06214b40e8787",
                "md5": "3deaf50b5c8b6c8fbb96af42a8c5368d",
                "sha256": "3c84312a12ab36ff2f7beeebeafeb5250973d2f89b93edf120cfe4d79a79a55f"
            },
            "downloads": -1,
            "filename": "slack_cleaner2-3.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "3deaf50b5c8b6c8fbb96af42a8c5368d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24276,
            "upload_time": "2024-06-15T14:59:16",
            "upload_time_iso_8601": "2024-06-15T14:59:16.909857Z",
            "url": "https://files.pythonhosted.org/packages/3d/52/b6e241fe93d4c0389ef342a55f4108d149b0890e0c16c2d06214b40e8787/slack_cleaner2-3.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-15 14:59:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sgratzl",
    "github_project": "slack_cleaner2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "slack_sdk",
            "specs": [
                [
                    ">=",
                    "3.13.0"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    ">=",
                    "0.4.4"
                ]
            ]
        },
        {
            "name": "python-dateutil",
            "specs": [
                [
                    ">=",
                    "2.8.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.26.0"
                ]
            ]
        }
    ],
    "lcname": "slack-cleaner2"
}
        
Elapsed time: 0.62275s