slack-cleaner2


Nameslack-cleaner2 JSON
Version 3.2.3 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_time2023-10-21 01:18:25
maintainer
docs_urlNone
authorSamuel Gratzl
requires_python
licenseMIT license
keywords slack_cleaner2 slack slack-cleaner
VCS
bugtrack_url
requirements No requirements were recorded.
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": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "slack_cleaner2 slack slack-cleaner",
    "author": "Samuel Gratzl",
    "author_email": "sam@sgratzl.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/7b/b8ad304995e5a72d54f0c93c7ae99ed7acb6ca02e4253219d03a2f27cfcc/slack_cleaner2-3.2.3.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.3",
    "project_urls": {
        "Homepage": "https://github.com/sgratzl/slack_cleaner2"
    },
    "split_keywords": [
        "slack_cleaner2",
        "slack",
        "slack-cleaner"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bce548bf9f3d34652b0966b86080b122a2c5aebcc843d897937162964666daec",
                "md5": "2a6499cbca3715ad2ce5f8999144936f",
                "sha256": "6e96388541e813035cb3efdb2315bc38aa73b2229b19001e093029beecdcd981"
            },
            "downloads": -1,
            "filename": "slack_cleaner2-3.2.3-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a6499cbca3715ad2ce5f8999144936f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 19769,
            "upload_time": "2023-10-21T01:18:23",
            "upload_time_iso_8601": "2023-10-21T01:18:23.765714Z",
            "url": "https://files.pythonhosted.org/packages/bc/e5/48bf9f3d34652b0966b86080b122a2c5aebcc843d897937162964666daec/slack_cleaner2-3.2.3-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e7bb8ad304995e5a72d54f0c93c7ae99ed7acb6ca02e4253219d03a2f27cfcc",
                "md5": "ac0db52c685c35af7d411e1363685c10",
                "sha256": "c9d4892d812e0925d9b91d10ec07f3f850b14d23878f18a309d776d24b465148"
            },
            "downloads": -1,
            "filename": "slack_cleaner2-3.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "ac0db52c685c35af7d411e1363685c10",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24251,
            "upload_time": "2023-10-21T01:18:25",
            "upload_time_iso_8601": "2023-10-21T01:18:25.485720Z",
            "url": "https://files.pythonhosted.org/packages/4e/7b/b8ad304995e5a72d54f0c93c7ae99ed7acb6ca02e4253219d03a2f27cfcc/slack_cleaner2-3.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-21 01:18:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sgratzl",
    "github_project": "slack_cleaner2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "slack-cleaner2"
}
        
Elapsed time: 0.13137s