Skip to content
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

delete specific bot by name #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions slack_cleaner/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(self):
# Conditions
p.add_argument('--user',
help='Delete messages/files from certain user')
p.add_argument('--botname',
help='Delete messages/files from certain bots')
p.add_argument('--bot', action='store_true',
help='Delete messages from bots')
p.add_argument('--after',
Expand Down Expand Up @@ -78,6 +80,7 @@ def __init__(self):
self.mpdirect_name = args.mpdirect

self.user_name = args.user
self.botname = args.botname
self.bot = args.bot
self.start_time = args.after
self.end_time = args.before
Expand Down
6 changes: 3 additions & 3 deletions slack_cleaner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_id_by_name(list_dict, key_name):
return d['id']


def clean_channel(channel_id, time_range, user_id=None, bot=False):
def clean_channel(channel_id, time_range, user_id=None, bot=False,botname=None):
# Setup time range for query
oldest = time_range.start_ts
latest = time_range.end_ts
Expand Down Expand Up @@ -111,7 +111,7 @@ def clean_channel(channel_id, time_range, user_id=None, bot=False):
delete_message_on_channel(channel_id, m)

# Delete bot messages
if bot and m.get('subtype') == 'bot_message':
if bot and m.get('subtype') == 'bot_message' and (botname == None or m.get('username') == botname) :
delete_message_on_channel(channel_id, m)

# Exceptions
Expand Down Expand Up @@ -308,7 +308,7 @@ def message_cleaner():
sys.exit('User not found')

# Delete messages on certain channel
clean_channel(_channel_id, time_range, _user_id, args.bot)
clean_channel(_channel_id, time_range, _user_id, args.bot, args.botname)


def file_cleaner():
Expand Down