Skip to content

Commit

Permalink
give a message if auth isn't setup, also fix white lists to work better
Browse files Browse the repository at this point in the history
  • Loading branch information
John Theodore committed Jun 26, 2018
1 parent 435cf61 commit acfa910
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions slack-autoarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def get_whitelist_keywords():

# remove whitespace characters like `\n` at the end of each line
keywords = map(lambda x: x.strip(), keywords)

if WHITELIST_KEYWORDS:
keywords.append(WHITELIST_KEYWORDS.split(','))
keywords = keywords + WHITELIST_KEYWORDS.split(',')
return keywords


Expand Down Expand Up @@ -73,7 +72,10 @@ def slack_api_http(api_endpoint=None, payload=None, method="GET", retry=True):
THROTTLE_REQUESTS -= 1
time.sleep(1.0)

if response.status_code == requests.codes.ok and response.json()['ok']:
if response.status_code == requests.codes.ok and 'error' in response.json() and response.json()['error'] == 'not_authed':
print('Need to setup auth.')
sys.exit(1)
elif response.status_code == requests.codes.ok and response.json()['ok']:
return response.json()
elif retry and response.status_code == requests.codes.too_many_requests:
THROTTLE_REQUESTS = 30
Expand Down Expand Up @@ -143,9 +145,10 @@ def is_channel_disused(channel, too_old_datetime):


# If you add channels to the WHITELIST_KEYWORDS constant they will be exempt from archiving.
def is_channel_whitelisted(channel, keywords):
for kw in keywords:
if kw in channel['name']:
def is_channel_whitelisted(channel, white_listed_channels):
for white_listed_channel in white_listed_channels:
wl_channel_name = white_listed_channel.strip('#')
if wl_channel_name in channel['name']:
return True
return False

Expand Down
2 changes: 2 additions & 0 deletions whitelist.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
channel1
channel2

0 comments on commit acfa910

Please sign in to comment.