From 54adc27983402e724894bdc59bcc7fa2b0f62065 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sat, 21 Mar 2020 13:25:12 +0100 Subject: Print warning when trying to add two tokens for the same team and user --- wee_slack.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index ce6a401..d2ab9b2 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -286,8 +286,9 @@ def colorize_string(color, string, reset_color='reset'): return string -def print_error(message, buffer=''): - w.prnt(buffer, '{}Error: {}'.format(w.prefix('error'), message)) +def print_error(message, buffer='', warning=False): + prefix = 'Warning' if warning else 'Error' + w.prnt(buffer, '{}{}: {}'.format(w.prefix('error'), prefix, message)) def format_exc_tb(): @@ -2730,6 +2731,15 @@ def handle_rtmstart(login_data, eventrouter, team, channel, metadata): ) ) return + elif metadata.metadata.get('initial_connection'): + print_error( + 'Ignoring duplicate Slack tokens for the same team ({}) and user ({}). The two ' + 'tokens are {}... and {}...'.format( + t.team_info["name"], t.nick, t.token[:15], metadata.token[:15] + ), + warning=True + ) + return else: t.set_reconnect_url(login_data['url']) t.connecting_rtm = False @@ -5013,7 +5023,8 @@ def initiate_connection(token, retries=3, team=None): 'rtm.{}'.format('connect' if team else 'start'), {"batch_presence_aware": 1}, retries=retries, - token=token) + token=token, + metadata={'initial_connection': True}) if __name__ == "__main__": -- cgit