diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-04-22 19:52:06 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-04-23 10:56:42 +0200 |
commit | cea09f871b52b72909cff733c97dd8e507d2fa5b (patch) | |
tree | 2bff1039cee7dea29c21c3355be0a41f8fbc27af /wee_slack.py | |
parent | f45a950fd5b9653903816261b2e1f2acdca1c588 (diff) | |
download | wee-slack-cea09f871b52b72909cff733c97dd8e507d2fa5b.tar.gz |
Call rtm.connect instead of rtm.start on reconnect
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py index 348e299..a4debc0 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -477,7 +477,7 @@ class EventRouter(object): elif return_code != -1: self.reply_buffer.pop(request_metadata.response_id, None) self.delete_context(data) - if request_metadata.request == 'rtm.start': + if request_metadata.request.startswith('rtm.'): retry_text = ('retrying' if request_metadata.should_try() else 'will not retry after too many failed attempts') w.prnt('', ('Failed connecting to slack team with token starting with {}, {}. ' + @@ -1273,7 +1273,7 @@ class SlackTeam(object): # The fast reconnect failed, so start over-ish for chan in self.channels: self.channels[chan].got_history = False - s = initiate_connection(self.token, retries=999) + s = initiate_connection(self.token, retries=999, team_hash=self.team_hash) self.eventrouter.receive(s) self.connecting = False # del self.eventrouter.teams[self.get_team_hash()] @@ -2521,6 +2521,18 @@ def handle_rtmstart(login_data, eventrouter): t.connect() +def handle_rtmconnect(login_data, eventrouter): + metadata = login_data["wee_slack_request_metadata"] + team = eventrouter.teams.get(metadata.team_hash) + + if not login_data["ok"]: + w.prnt("", "ERROR: Failed reconnecting to Slack with token starting with {}: {}" + .format(metadata.token[:15], login_data["error"])) + return + + team.set_reconnect_url(login_data['url']) + team.connect() + def handle_emojilist(emoji_json, eventrouter, **kwargs): if emoji_json["ok"]: @@ -4536,11 +4548,12 @@ def trace_calls(frame, event, arg): return -def initiate_connection(token, retries=3): +def initiate_connection(token, retries=3, team_hash=None): return SlackRequest(token, - 'rtm.start', + 'rtm.{}'.format('connect' if team_hash else 'start'), {"batch_presence_aware": 1}, - retries=retries) + retries=retries, + team_hash=team_hash) if __name__ == "__main__": |