aboutsummaryrefslogtreecommitdiffstats
path: root/slack/init.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-01-15 01:43:25 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit02cf9e43839ee1747c07e1f2c8c7b6ecc24518cc (patch)
tree8ea7d4d8d1d0c7e7826a7d06bb18fb8afd44d484 /slack/init.py
parent6598b7a77c0b590fcece218b9bf065301c3ee82d (diff)
downloadwee-slack-02cf9e43839ee1747c07e1f2c8c7b6ecc24518cc.tar.gz
Ping websocket every 5 seconds
Diffstat (limited to 'slack/init.py')
-rw-r--r--slack/init.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/slack/init.py b/slack/init.py
index e039d9c..dd3c080 100644
--- a/slack/init.py
+++ b/slack/init.py
@@ -1,6 +1,9 @@
from __future__ import annotations
+import socket
+
import weechat
+from websocket import WebSocketConnectionClosedException
from slack.commands import register_commands
from slack.config import SlackConfig
@@ -53,6 +56,19 @@ def modifier_input_text_display_with_cursor_cb(
return prefix + string
+def ws_ping_cb(data: str, remaining_calls: int) -> int:
+ for workspace in shared.workspaces.values():
+ if workspace.is_connected:
+ try:
+ workspace.ws.ping()
+ # workspace.last_ping_time = time.time()
+ except (WebSocketConnectionClosedException, socket.error) as e:
+ # TODO: Handle error
+ # handle_socket_error(e, team, "ping")
+ print(e)
+ return weechat.WEECHAT_RC_OK
+
+
async def init():
auto_connect = weechat.info_get("auto_connect", "") == "1"
if auto_connect:
@@ -89,5 +105,6 @@ def main():
get_callback_name(modifier_input_text_display_with_cursor_cb),
"",
)
+ weechat.hook_timer(5000, 0, 0, get_callback_name(ws_ping_cb), "")
create_task(init())