aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2020-03-21 12:56:40 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2020-03-21 13:25:04 +0100
commitba400e4f884cc642e1565ee9b4b268943dcef742 (patch)
tree7edfd782dba87af17555a75718e63f285233d8ac /wee_slack.py
parentd36b1f201c7736cf1a257ccfe594feffe4e7cb28 (diff)
downloadwee-slack-ba400e4f884cc642e1565ee9b4b268943dcef742.tar.gz
Print error when trying to add the same team for two different users
This is not currently supported because the two teams would have conflicting buffer names. Before this patch, it would print out a bunch of error messages about conflicting buffer names.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 35170c6..ce6a401 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1377,8 +1377,8 @@ class SlackTeam(object):
return self.team_hash
@staticmethod
- def generate_team_hash(nick, subdomain):
- return str(sha1_hex("{}{}".format(nick, subdomain)))
+ def generate_team_hash(team_id, subdomain):
+ return str(sha1_hex("{}{}".format(team_id, subdomain)))
def refresh(self):
self.rename()
@@ -2658,8 +2658,15 @@ def handle_rtmstart(login_data, eventrouter, team, channel, metadata):
return
+ self_profile = next(
+ user["profile"]
+ for user in login_data["users"]
+ if user["id"] == login_data["self"]["id"]
+ )
+ self_nick = nick_from_profile(self_profile, login_data["self"]["name"])
+
# Let's reuse a team if we have it already.
- th = SlackTeam.generate_team_hash(login_data['self']['name'], login_data['team']['domain'])
+ th = SlackTeam.generate_team_hash(login_data['team']['id'], login_data['team']['domain'])
if not eventrouter.teams.get(th):
users = {}
@@ -2694,13 +2701,6 @@ def handle_rtmstart(login_data, eventrouter, team, channel, metadata):
else:
channels[item["id"]] = SlackGroupChannel(eventrouter, **item)
- self_profile = next(
- user["profile"]
- for user in login_data["users"]
- if user["id"] == login_data["self"]["id"]
- )
- self_nick = nick_from_profile(self_profile, login_data["self"]["name"])
-
t = SlackTeam(
eventrouter,
metadata.token,
@@ -2721,8 +2721,18 @@ def handle_rtmstart(login_data, eventrouter, team, channel, metadata):
else:
t = eventrouter.teams.get(th)
- t.set_reconnect_url(login_data['url'])
- t.connecting_rtm = False
+ if t.myidentifier != login_data["self"]["id"]:
+ print_error(
+ 'The Slack team {} has tokens for two different users, this is not supported. The '
+ 'token {}... is for user {}, and the token {}... is for user {}. Please remove '
+ 'one of them.'.format(
+ t.team_info["name"], t.token[:15], t.nick, metadata.token[:15], self_nick
+ )
+ )
+ return
+ else:
+ t.set_reconnect_url(login_data['url'])
+ t.connecting_rtm = False
t.connect()