99import sys
1010import threading
1111import importlib .metadata
12+ import time
1213import traceback
1314from typing import (
1415 Callable ,
@@ -755,16 +756,16 @@ def register_client(server_url: str, client_uuid: str = "") -> None:
755756 client_uuid = str (uuid .uuid4 ())
756757
757758 # Create the WebSocket connection
758- with syncconnect ( f" { server_url } / { client_uuid } " ) as websocket :
759- server_version = str ( websocket . recv ())
760- print ( f"Server version: { server_version } " )
761- client_version = importlib . metadata . version ( "wcgw " )
762- websocket . send ( client_version )
763-
764- print (
765- f"Connected. Share this user id with the chatbot: { client_uuid } \n Link: https://chatgpt.com/g/g-Us0AAXkRh-wcgw-giving-shell-access"
766- )
767- try :
759+ try :
760+ with syncconnect ( f" { server_url } / { client_uuid } " ) as websocket :
761+ server_version = str ( websocket . recv () )
762+ print ( f"Server version: { server_version } " )
763+ client_version = importlib . metadata . version ( "wcgw" )
764+ websocket . send ( client_version )
765+
766+ print (
767+ f"Connected. Share this user id with the chatbot: { client_uuid } \n Link: https://chatgpt.com/g/g-Us0AAXkRh-wcgw-giving-shell-access"
768+ )
768769 while True :
769770 # Wait to receive data from the server
770771 message = websocket .recv ()
@@ -783,9 +784,10 @@ def register_client(server_url: str, client_uuid: str = "") -> None:
783784 assert isinstance (output , str )
784785 websocket .send (output )
785786
786- except (websockets .ConnectionClosed , ConnectionError , OSError ):
787- print (f"Connection closed for UUID: { client_uuid } , retrying" )
788- register_client (server_url , client_uuid )
787+ except (websockets .ConnectionClosed , ConnectionError , OSError ):
788+ print (f"Connection closed for UUID: { client_uuid } , retrying" )
789+ time .sleep (0.5 )
790+ register_client (server_url , client_uuid )
789791
790792
791793run = Typer (pretty_exceptions_show_locals = False , no_args_is_help = True )
0 commit comments