from websockets.sync.client import connect from dotenv import load_dotenv import json import random import os load_dotenv() websocket_port = os.environ.get("WEBSOCKET_PORT") def is_simplex_link_valid(simplex_link: str) -> bool: """ Connects to the group using the `simplex_link`. If the response contains error False will be returned else True. """ with connect(f"ws://localhost:{websocket_port}") as websocket: query = f"/c incognito {simplex_link}" command = { 'corrId': f"id{random.randint(0,999999)}", 'cmd': query, } websocket.send(json.dumps(command)) message = websocket.recv() response = json.loads(message) response_type = response['resp']['type'] # print(response) if 'error' in response_type.lower(): return False elif 'deleted' in response_type.lower(): return False print('[+] Success!',response_type) return True if __name__ == '__main__': sxclink='https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2FBD4qkVq8lJUgjHt0kUaxeQBYsKaxDejeecxm6-2vOwI%3D%40b6geeakpwskovltbesvy3b6ah3ewxfmnhnshojndmpp7wcv2df7bnead.onion%2F4woLIDlpkvXRvZmaAiWA802OwiyxekdJ%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEAzIAoE-OWDqFJXMqgunIWHPpE_u7e52Wtu8TioPc1QwI%253D&data=%7B%22groupLinkId%22%3A%22Srr1_MNob7WfPTQIY-ug5Q%3D%3D%22%7D' is_simplex_link_valid(sxclink)