Skip to content

Commit

Permalink
https://github.com/kfei/slack-cleaner/pull/24
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Sep 8, 2017
1 parent a87a3f0 commit c7294fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ slack-cleaner --token <TOKEN> --file --user johndoe
# Delete all snippets and images
slack-cleaner --token <TOKEN> --file --types snippets,images

# Purge messages from all channels for a user
slack-cleaner --token <TOKEN> --message --purge yes --user johndoe

# Always have a look at help message
slack-cleaner --help
```
Expand Down
3 changes: 3 additions & 0 deletions slack_cleaner/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self):

# Channel, DM or group
g_chan = p.add_mutually_exclusive_group()
g_chan.add_argument('--purge',
help='Purge messages from all channels')
g_chan.add_argument('--channel',
help='Channel name\'s, e.g., general')
g_chan.add_argument('--direct',
Expand Down Expand Up @@ -81,6 +83,7 @@ def __init__(self):
self.delete_message = args.message
self.delete_file = args.file

self.purge_name = args.purge
self.channel_name = args.channel
self.direct_name = args.direct
self.group_name = args.group
Expand Down
23 changes: 22 additions & 1 deletion slack_cleaner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
# User dict
user_dict = {}

# Channel dict
channel_dict = {}

# Construct a local user dict for further usage
def init_user_dict():
Expand All @@ -60,12 +62,29 @@ def init_user_dict():
# Init user dict
init_user_dict()

# Construct a local channel dict for further usage
def init_channel_dict():
res = slack.channels.list().body
if not res['ok']:
return
channels = res['channels']

for c in channels:
channel_dict[c['id']] = c['name']

# Init channel dict
init_channel_dict()

def get_id_by_name(list_dict, key_name):
for d in list_dict:
if d['name'] == key_name:
return d['id']

def purge_channels(time_range, user_id=None, bot=False):

for c in channel_dict:
print "Cleaning Channel: ",channel_dict[c]
clean_channel(c, time_range, user_id, args.bot)

def clean_channel(channel_id, time_range, user_id=None, bot=False, keep_pinned=False):
# Setup time range for query
Expand All @@ -74,7 +93,9 @@ def clean_channel(channel_id, time_range, user_id=None, bot=False, keep_pinned=F

_api_end_point = None
# Set to the right API end point
if args.channel_name:
if args.purge_name:
_api_end_point = slack.channels.history
elif args.channel_name:
_api_end_point = slack.channels.history
elif args.direct_name:
_api_end_point = slack.im.history
Expand Down

0 comments on commit c7294fb

Please sign in to comment.