-
-
Notifications
You must be signed in to change notification settings - Fork 42
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migration guides to slack_cleaner2 #79
Comments
Show Information about the Slack Workspaceslack-cleaner --token <TOKEN> --info will become
from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>")
print('users', s.users)
print('public channels', s.channels)
print('private channels', s.groups)
print('instant messages', s.ims)
print('multi user direct messages', s.mpim) python info.py |
Delete all messages from the general channelslack-cleaner --token <TOKEN> --rate 1 --message --channel general --user "*" will become clean_general.py from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>", sleep_for=1)
for msg in s.c.general.msgs(with_replies=True):
msg.delete() python clean_general.py |
Delete all messages from bots (especially flooding CI updates)slack-cleaner --token <TOKEN> --rate 1 --message --channel auto-build --bot will become clean_bot.py from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>", sleep_for=1)
for msg in s.c['auto-build'].msgs():
if msg.bot:
msg.delete() python clean_bot.py |
Delete all messages older than 2015/09/19slack-cleaner --token <TOKEN> --rate 1 --message --channel general --user "*" --before 20150919 will become clean_general_before2015.py from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>", sleep_for=1)
for msg in s.c.general.msgs(before="20150919", with_replies=True):
msg.delete() python clean_general_before2015.py |
what if user is "sam" instead of "*" which seems to be the default? IS there a way to filter for that? |
Delete all messages in channel general by user named sam but keep pinned messagesslack-cleaner --token <TOKEN> --rate 1 --message --channel general --user "sam" --keeppinned will become clean_general_sam.py from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>", sleep_for=1)
for msg in s.c.general.msgs(with_replies=True):
if msg.user.name == 'sam' and not msg.pinned_to:
msg.delete() python clean_general_sam.py alternative using predicate syntax (untested) clean_general_sam_predicate.py from slack_cleaner2 import SlackCleaner, is_not_pinned, match_user
s = SlackCleaner("<TOKEN>", sleep_for=1)
for msg in filter(is_not_pinned() and match_user('sam'), s.c.general.msgs(with_replies=True)):
msg.delete() |
Hi @sgratzl is there a way to clean msg in multiple channels instead of repeating the entire script? |
Delete all messages in all channelsslack-cleaner --token <TOKEN> --rate 1 --message --channel ".*" --regex --user "*" will become clean_all.py from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>", sleep_for=1)
for channel in s.conversations:
for msg in channel.msgs(with_replies=True):
msg.delete() python clean_all.py |
Hey sgratzl, |
from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>", sleep_for=1)
for channel in s.conversations:
for msg in channel.msgs():
if not next(msg.replies(), None): # replies are empty
msg.delete() or using some internal knowledge what makes message starting a thread start from slack_cleaner2 import SlackCleaner
s = SlackCleaner("<TOKEN>", sleep_for=1)
for channel in s.conversations:
for msg in channel.msgs():
if 'thread_ts' not in msg.json: #reply thread_ts info is not set
msg.delete() |
Why not offer both, i.e., users that need more control code in python users that just want to delete message from a channel use the script args and this is internally mapped to what you've written here? |
Delete all files: #!/usr/bin/env python
from slack_cleaner2 import SlackCleaner
s = SlackCleaner('<TOKEN (xoxp-...)>')
for file in s.files():
print(f'Deleting: {file}')
file.delete() |
Agreed - adding a thin command line client on top of the library, that handles common cases seems like it would take just about the same amount of time as listing the code for the common cases on this page. At the same time, I really appreciate what @sgratzl has already provided for us here. |
Ok |
|
I'm wondering if someone would be kind enough to post an example of deleting a whole thread of direct (instant) messages with another specific user, say Leroy? Thanks in advance - I'm only half able to understand the available examples and my python skills are not what I'd hope they'd be at the moment... Below is what I've been attempting, but I think there's loads wrong....
|
Is there a way to specify
|
@nasalaika: you can do it like this. from slack_cleaner2 import SlackCleaner
s = SlackCleaner(<TOKEN>, sleep_for=1)
for c in s.ims:
if c.name == 'leroy':
for msg in c.msgs():
if msg.user == s.myself:
msg.delete() Bear in mind that the Slack API doesn't permit the deletion of direct messages that are not written by you, so Leroy would have to delete his half of the conversation. |
seems like it couldn't find the channel named |
cannot delete entry: xxxxx:1624088712.0007 (xxxxxxxx (xxxxxxxxxxxxx) SERHAT BARLAS) cant_delete_message When I want to delete all messages, I cannot delete the messages of the error user |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Slack Cleaner v2 at https://github.com/sgratzl/slack_cleaner2 is an improved version of this slack cleaner script. It is easier to maintain and more powerful. However, instead of a single script to execute it is a Python library module. Thus, it requires to code in Python.
This issue is a collection of common examples in
slack-cleaner
and their counterpart inslack_cleaner2
In each example
<TOKEN>
needs to be replaced by the corresponding Slack API tokenThe text was updated successfully, but these errors were encountered: