diff options
-rw-r--r-- | wee_slack.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/wee_slack.py b/wee_slack.py index 1bd671f..fc62b2d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -145,6 +145,7 @@ class SlackServer(object): self.channels = SearchList() self.connecting = False self.connected = False + self.connection_attempt_time = 0 self.communication_counter = 0 self.message_buffer = {} self.ping_hook = None @@ -206,10 +207,24 @@ class SlackServer(object): request = {"type": "ping"} self.send_to_websocket(request) + def should_connect(self): + """ + If we haven't tried to connect OR we tried and never heard back and it + has been 65 seconds consider the attempt dead and try again + """ + if self.connection_attempt_time == 0 or self.connection_attempt_time + 65 > int(time.time()): + return true + else: + return false + def connect_to_slack(self): t = time.time() + #Double check that we haven't exceeded a long wait to connect and try again. + if self.connecting == True and should_connect(): + self.connecting = False if not self.connecting: async_slack_api_request("slack.com", self.token, "rtm.start", {"ts": t}) + self.connection_attempt_time = int(time.time()) self.connecting = True def connected_to_slack(self, login_data): @@ -2373,7 +2388,7 @@ if __name__ == "__main__": users = SearchList() w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_changed_cb", "") - w.hook_timer(30000, 0, 0, "slack_connection_persistence_cb", "") + w.hook_timer(3000, 0, 0, "slack_connection_persistence_cb", "") # attach to the weechat hooks we need w.hook_timer(1000, 0, 0, "typing_update_cb", "") |