Skip to content

Commit fb42924

Browse files
authored
Added 8 new request functions
Unfortunately, many of the endpoints I tested were developer only. So users and bots cannot use them. You'll see them as disabled functions in this release. Only 8/18 work... Really a bummer as these are all endpoints bots should be able to use. Though I cannot do anything about that. The new request functions are: ``` bot.request_pending_requests(group_id) bot.request_member_info(group_id, player_id) bot.request_check_pending_invites(group_id) bot.request_server_by_name(server_name) bot.request_group_by_id(group_id) bot.request_search_userid(player_id) bot.request_check_user_role(group_id, player_id, role_int) bot.request_group_bans(group_id) ``` This release also fixed an issue of crashing if no user account was provided... whoops! This release ALSO fixes a bug that caused the InfoLog subscription to crash the program. (hopefully)
1 parent 8a4429a commit fb42924

File tree

1 file changed

+143
-20
lines changed

1 file changed

+143
-20
lines changed

py_tale.py

Lines changed: 143 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ async def new_console_websocket(self, addr, port, server_id, token): # Uses SERV
112112
while True:
113113
var = await websocket.recv()
114114
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
118115
if var["type"] == "CommandResult":
119116
self.websocket_responses[int(var["commandId"])] = var
120117
if self.debug:
@@ -123,17 +120,15 @@ async def new_console_websocket(self, addr, port, server_id, token): # Uses SERV
123120
if server_id in self.console_subscriptions:
124121
if var["eventType"] in self.console_subscriptions[server_id]:
125122
for function in self.console_subscriptions[server_id][var["eventType"]]:
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
128-
asyncio.create_task(function(content)) # call each function and pass the data.
123+
var["server_id"] = server_id
124+
asyncio.create_task(function(var)) # call each function and pass the data.
129125
if self.debug:
130126
print(Fore.GREEN + str(datetime.now()).split(".")[0], "||", f"[RECEIVED] (console {server_id} websocket)< {var}", end=Style.RESET_ALL + "\n")
131127
if self.debug:
132128
print(Fore.RED + str(datetime.now()).split(".")[0], "||", f"Console websocket for server {server_id} closed.", end=Style.RESET_ALL + "\n") # This should never be called, but just in case.
133129
except Exception as e:
134130
print(Fore.RED + str(datetime.now()).split(".")[0], "||", f"Server console {server_id} failed. Error details listed below:\n", e, end=Style.RESET_ALL + "\n")
135131
print(Fore.RED + str(datetime.now()).split(".")[0], "||", "The server likely shutdown. I'll try to start the console again when the server is back up!", end=Style.RESET_ALL + "\n")
136-
print(Fore.YELLOW + str(traceback.print_exc()), end=Style.RESET_ALL + "\n")
137132
if server_id in self.console_websockets:
138133
del self.console_websockets[server_id]
139134

@@ -306,17 +301,92 @@ async def request_post_console(self, server_id, body='{"should_launch":"false","
306301
console_res = json.loads(console_res)
307302
return console_res
308303

309-
async def request_ban_player(self, group_id, player_id): #Not even going to test this one. It's irreversible
310-
raise FunctionDisabledException("request_ban_player: This has been disabled due to console bans being irreversible. Remove the raise Exception line at the top of the function in py_tale to use.")
304+
async def request_ban_player(self, group_id, player_id):
311305
await self.wait_for_ready()
312-
code = requests.post(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/groups/{group_id}/bans/{player_id}", headers=self.ws_headers)
313-
return code
306+
ban = requests.post(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/groups/{group_id}/bans/{player_id}", headers=self.ws_headers)
307+
print(ban.status_code, ban.content)
308+
ban = ban.content.decode('utf-8')
309+
ban = json.loads(ban)
310+
return ban
314311

315-
async def request_unban_player(self, group_id, player_id): #Not even going to test this one. It's irreversible
316-
raise FunctionDisabledException("request_unban_player: This has been disabled due to console bans being irreversible. Remove the raise Exception line at the top of the function in py_tale to use.")
312+
async def request_unban_player(self, group_id, player_id):
317313
await self.wait_for_ready()
318-
code = requests.delete(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/groups/{group_id}/bans/{player_id}", headers=self.ws_headers)
319-
return code
314+
unban = requests.delete(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/groups/{group_id}/bans/{player_id}", headers=self.ws_headers)
315+
unban = unban.content.decode('utf-8')
316+
unban = json.loads(unban)
317+
return unban
318+
319+
async def request_group_bans(self, group_id):
320+
await self.wait_for_ready()
321+
ban_list = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}/bans", headers=self.ws_headers)
322+
ban_list = ban_list.content.decode('utf-8')
323+
ban_list = json.loads(ban_list)
324+
return ban_list
325+
326+
async def request_user_discord(self, player_id): #may not be possible via bot, instead a user may need to do this
327+
return FunctionDisabledException("Looks like devs/mods only have permissions to get discords from players...")
328+
await self.wait_for_ready()
329+
user_discord = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Account/discord/{player_id}", headers=self.user_headers)
330+
print(user_discord.status_code)
331+
user_discord = user_discord.content.decode('utf-8')
332+
print(user_discord)
333+
user_discord = json.loads(user_discord)
334+
return user_discord
335+
336+
async def request_linked_accounts(self, player_id):
337+
await self.wait_for_ready()
338+
user_links = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/linked/{player_id}/linked", headers=self.user_headers)
339+
user_links = user_links.content.decode('utf-8')
340+
user_links = json.loads(user_links)
341+
return user_links
342+
343+
async def request_recent_players(self, server_id):
344+
return FunctionDisabledException("request_recent_players works, but doesn't actually provide any data at all. Unfortunate.")
345+
await self.wait_for_ready()
346+
recent = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/recent-players/server/{server_id}", headers=self.user_headers)
347+
print(recent.content, recent.status_code)
348+
recent = recent.content.decode('utf-8')
349+
recent = json.loads(recent)
350+
return recent
351+
352+
async def request_user_stats(self, player_id): #may not be possible via bot, instead a user may need to do this
353+
return FunctionDisabledException("request_user_stats does not work. Must be a dev only command...")
354+
await self.wait_for_ready()
355+
user_stats = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Users/{player_id}/statistics", headers=self.user_headers)
356+
print(user_stats.status_code, user_stats.content)
357+
user_stats = user_stats.content.decode('utf-8')
358+
user_stats = json.loads(user_stats)
359+
return user_stats
360+
361+
async def request_pending_requests(self, group_id):
362+
await self.wait_for_ready()
363+
pending_requests = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}/requests", headers=self.ws_headers)
364+
pending_requests = pending_requests.content.decode('utf-8')
365+
pending_requests = json.loads(pending_requests)
366+
return pending_requests
367+
368+
async def request_to_join(self, group_id):
369+
return FunctionDisabledException("request_to_join Not possible for bot accounts... Which is kinda the whole idea... So yeah...")
370+
await self.wait_for_ready()
371+
join = requests.post(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}/requests", headers=self.ws_headers)
372+
print(join.status_code, join.content)
373+
join = join.content.decode('utf-8')
374+
join = json.loads(join)
375+
return join
376+
377+
async def request_member_info(self, group_id, player_id):
378+
await self.wait_for_ready()
379+
member = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}/members/{player_id}", headers=self.ws_headers)
380+
member = member.content.decode('utf-8')
381+
member = json.loads(member)
382+
return member
383+
384+
async def request_check_pending_invites(self, group_id):
385+
await self.wait_for_ready()
386+
pending_requests = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}/invites", headers=self.ws_headers)
387+
pending_requests = pending_requests.content.decode('utf-8')
388+
pending_requests = json.loads(pending_requests)
389+
return pending_requests
320390

321391
async def request_approve_invite(self, group_id, player_id): # Does not work. Going to have to check this... response 405
322392
await self.wait_for_ready()
@@ -357,6 +427,20 @@ async def request_server_by_id(self, server_id): # Uses SERVER id. - verified
357427
server_info = json.loads(server_info)
358428
return server_info
359429

430+
async def request_server_by_name(self, server_name): # same as request_server_by_id but with a string name.
431+
await self.wait_for_ready()
432+
server_info = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/servers/name/{server_name}", headers=self.ws_headers)
433+
server_info = server_info.content.decode('utf-8')
434+
server_info = json.loads(server_info)
435+
return server_info
436+
437+
async def request_group_by_id(self, group_id): # Uses GROUP id. - verified
438+
await self.wait_for_ready()
439+
group_info = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}", headers=self.ws_headers)
440+
group_info = group_info.content.decode('utf-8')
441+
group_info = json.loads(group_info)
442+
return group_info
443+
360444
async def request_accept_invite(self, group_id): # Uses GROUP id. - verified
361445
await self.wait_for_ready() # Accepts an invite to a server
362446
accept = requests.post(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/groups/invites/{group_id}", headers=self.ws_headers)
@@ -395,12 +479,50 @@ async def request_search_username(self, username): # Bots can't do this apparent
395479
if self.user_initialized:
396480
await self.wait_for_ready()
397481
body = '{"username":"' + username + '"}'
398-
result = requests.post("https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/users/search/username", headers=self.user_headers, data=body)
399-
result = json.loads(result.content)
400-
return result
482+
player_info = requests.post("https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/users/search/username", headers=self.user_headers, data=body)
483+
player_info = json.loads(player_info.content)
484+
return player_info
401485
else:
402486
raise FunctionDisabledException("request_search_name currently does not work for bot accounts. You'll need to add a user login to the config function.")
403487

488+
async def request_search_userid(self, player_id): # Bots can't do this apparently... (but users can!)
489+
if self.user_initialized:
490+
await self.wait_for_ready()
491+
player_info = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/users/{player_id}", headers=self.user_headers)
492+
player_info = json.loads(player_info.content)
493+
return player_info
494+
else:
495+
raise FunctionDisabledException("request_search_userid currently does not work for bot accounts. You'll need to add a user login to the config function.")
496+
497+
async def request_user_permissions(self, player_id):
498+
return FunctionDisabledException("request_user_permissions Dev only command...")
499+
user_perms = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Users/{player_id}/permissions", headers=self.user_headers)
500+
print(user_perms.content, user_perms.status_code)
501+
user_perms = user_perms.content.decode('utf-8')
502+
user_perms = json.loads(user_perms)
503+
return user_perms
504+
505+
async def request_change_member_role(self, group_id, player_id, role_int): # 1 is member, 2 is moderator and 7 is owner role.
506+
return FunctionDisabledException("request_change_member_role Bot accounts do not seem capable of doing this... Making a user able to do it would be meaningless...")
507+
change_role = requests.post(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}/members/{player_id}/role/{role_int}", headers=self.ws_headers)
508+
change_role = change_role.content.decode('utf-8')
509+
change_role = json.loads(change_role)
510+
return change_role
511+
512+
async def request_user_achievements(self, player_id):
513+
return FunctionDisabledException("request_user_achievements is a dev only command seemingly...")
514+
user_achievements = requests.get(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/users/{player_id}/achievements", headers=self.user_headers)
515+
print(user_achievements.content,user_achievements.status_code)
516+
user_achievements = user_achievements.content.decode('utf-8')
517+
user_achievements = json.loads(user_achievements)
518+
return user_achievements
519+
520+
async def request_check_user_role(self, group_id, player_id, role_int):
521+
body = f"{{\"permissions\":[{role_int}]}}"
522+
user_perms = requests.post(f"https://967phuchye.execute-api.ap-southeast-2.amazonaws.com/prod/api/Groups/{group_id}/{player_id}/permissions/check", headers=self.ws_headers, data=body)
523+
user_perms = user_perms.content.decode('utf-8')
524+
user_perms = json.loads(user_perms)
525+
return user_perms
404526

405527
async def request_consoles(self):
406528
await self.wait_for_ready()
@@ -572,8 +694,9 @@ def config(self, client_id, client_secret, scope_string, user_id, debug=False, u
572694
'client_id': self.client_id,
573695
'client_secret': self.client_secret
574696
}
575-
if len(user_password) != 128: # Lazy way of checking if passed password is a hash or plain text.
576-
print(Fore.RED + "Warning! It is recommended to use a sha512 hash of your password, rather than plain text.\nContinuing as normal...", end=Style.RESET_ALL + "\n")
697+
if user_password != None:
698+
if len(user_password) != 128: # Lazy way of checking if passed password is a hash or plain text.
699+
print(Fore.RED + "Warning! It is recommended to use a sha512 hash of your password, rather than plain text.\nContinuing as normal...", end=Style.RESET_ALL + "\n")
577700

578701
async def ping_websocket(self): # Function to periodically ping the websocket to keep connection alive.
579702
try:

0 commit comments

Comments
 (0)