Replies: 23 comments 4 replies
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
what if user is "sam" instead of "*" which seems to be the default? IS there a way to filter for that? |
Beta Was this translation helpful? Give feedback.
-
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() |
Beta Was this translation helpful? Give feedback.
-
Hi @sgratzl is there a way to clean msg in multiple channels instead of repeating the entire script? |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Hey sgratzl, |
Beta Was this translation helpful? Give feedback.
-
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() |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
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() |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
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....
|
Beta Was this translation helpful? Give feedback.
-
Is there a way to specify
|
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
seems like it couldn't find the channel named |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
delete all messages from a specific thread, you just need to pass the url as an argument.
|
Beta Was this translation helpful? Give feedback.
-
Hi sgratzl, I'm trying to download files within a specific IM. When I run the below code I can only download the same 10 files at a time. If if I delete those files I can get 10 new ones but it seems I'm locked into a limit of 10 files at a time. Is file download count limited to 10 at a time? If so, can this be altered to support downloading a larger numbers of files at a time?
|
Beta Was this translation helpful? Give feedback.
-
I am trying to delete all my replies to all messages in a specific IM. In other words, in my private messages with John, I would like to delete every instance where I replied to one of his messages (or one of my own messages) in a thread. Is there a way to do this? EDIT: I figured it out
|
Beta Was this translation helpful? Give feedback.
-
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 tokenBeta Was this translation helpful? Give feedback.
All reactions