Skip to content

Commit 28b59b9

Browse files
authored
Fixed string auto-escape making some subs crash
Fixed a bug that prevented some subscriptions containing a dict/json as a string value from crashing the program. Also removed an annoying yellow debug line, and removed a redundant re-declaration of self.user_password and self.user_name. Basically a small cleanup and a stability update.
1 parent 7a3fa9b commit 28b59b9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

py_tale.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ def __init__(self): # Function that automatically declares variables
8383
self.jsonResponse = {}
8484
self.ws_headers = {}
8585
self.user_headers = {}
86-
self.user_name = None
87-
self.user_password = None
8886
self.data = {
8987
'grant_type': 'client_credentials',
9088
'scope': self.scope_string,
@@ -113,8 +111,10 @@ async def new_console_websocket(self, addr, port, server_id, token): # Uses SERV
113111
print(Fore.CYAN + str(datetime.now()).split(".")[0], "||", f"[SENT] (console {server_id} websocket)> {to_send}", end=Style.RESET_ALL + "\n") # end = Style.RESET_ALL prevents other prints from containing the set color
114112
while True:
115113
var = await websocket.recv()
116-
print(Fore.YELLOW + "!var: " + str(var), end=Style.RESET_ALL + "\n")
117114
var = json.loads(var)
115+
if "data" in var.keys():
116+
if "message" in var["data"]:
117+
var["data"]["message"] = var["data"]["message"] # Leaving this here in case I wanna change stuff about it, really does nothing rn
118118
if var["type"] == "CommandResult":
119119
self.websocket_responses[int(var["commandId"])] = var
120120
if self.debug:
@@ -123,7 +123,8 @@ async def new_console_websocket(self, addr, port, server_id, token): # Uses SERV
123123
if server_id in self.console_subscriptions:
124124
if var["eventType"] in self.console_subscriptions[server_id]:
125125
for function in self.console_subscriptions[server_id][var["eventType"]]:
126-
content = json.loads(f"{{'server_id':{server_id},{str(var)[1:]}".replace("'", '"')) # Returns SERVER id, not GROUP id
126+
print(f"{{'server_id':{server_id}, {json.dumps(var)[1:]}".replace("'", '"'))
127+
content = json.loads(f"{{'server_id':{server_id},{json.dumps(var)[1:]}".replace("'", '"')) # Returns SERVER id, not GROUP id
127128
asyncio.create_task(function(content)) # call each function and pass the data.
128129
if self.debug:
129130
print(Fore.GREEN + str(datetime.now()).split(".")[0], "||", f"[RECEIVED] (console {server_id} websocket)< {var}", end=Style.RESET_ALL + "\n")

0 commit comments

Comments
 (0)