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

added the ability to use channels/groups with files #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions slack_cleaner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_user_name(m):
counter.increase()


def remove_files(time_range, user_id=None, types=None):
def remove_files(time_range, user_id=None, types=None, channel_id=None):
# Setup time range for query
oldest = time_range.start_ts
latest = time_range.end_ts
Expand All @@ -174,6 +174,7 @@ def remove_files(time_range, user_id=None, types=None):
has_more = True
while has_more:
res = slack.files.list(user=user_id, ts_from=oldest, ts_to=latest,
channel=channel_id,
types=types, page=page).body

if not res['ok']:
Expand Down Expand Up @@ -314,6 +315,15 @@ def message_cleaner():
def file_cleaner():
_user_id = None
_types = None
_channel_id = None

# If channel's name is supplied
if args.channel_name:
_channel_id = get_channel_id_by_name(args.channel_name)

# If group's name is supplied
if args.group_name:
_channel_id = get_group_id_by_name(args.group_name)

if args.user_name:
# A little bit tricky here, we use -1 to indicates `--user=*`
Expand All @@ -328,7 +338,11 @@ def file_cleaner():
if args.types:
_types = args.types

remove_files(time_range, _user_id, _types)
if (args.channel_name or args.group_name) and _channel_id is None:
sys.exit('Channel, direct message or private group not found')

remove_files(time_range, user_id=_user_id, types=_types,
channel_id=_channel_id)


def main():
Expand Down