|
@@ -37,8 +37,14 @@ def get_users():
|
|
|
print(tn.read_until(b"\n").decode("ascii"))
|
|
|
print("----")
|
|
|
|
|
|
- # TODO clean this nicely
|
|
|
- client_info = {info["client_nickname"]: info for info in [{k: v for k, v in [i.split("=", 1) for i in ent.split()]} for ent in response.split("|")] if "serveradmin" not in info["client_nickname"]}
|
|
|
+ # entries separated by |'s
|
|
|
+ entries = response.split("|")
|
|
|
+ # entries contain key=value pairs separated by spaces
|
|
|
+ pairs = [[pr.split("=", 1) for pr in ent.split()] for ent in entries]
|
|
|
+ # rearrange these into maps for convenience
|
|
|
+ entry_maps = [{k: v for k, v in pr} for pr in pairs]
|
|
|
+ # combine the maps into one large map, ignoring serveradmin query user
|
|
|
+ client_info = {info["client_nickname"]: info for info in entry_maps if "serveradmin" not in info["client_nickname"]}
|
|
|
|
|
|
for k, v in client_info.items():
|
|
|
tn.write(f"clientinfo clid={v['clid']}\n".encode("utf-8"))
|
|
@@ -47,27 +53,38 @@ def get_users():
|
|
|
print(response)
|
|
|
print(tn.read_until(b"\n").decode("ascii"))
|
|
|
print("----")
|
|
|
- v["client_info"] = {k: v for k, v in [ent.split("=", 1) for ent in response.split() if "=" in ent]}
|
|
|
+
|
|
|
+ # info is key=value pairs separated by spaces
|
|
|
+ pairs = [ent.split("=", 1) for ent in response.split() if "=" in ent]
|
|
|
+ # rearrange into a map and put in the client_info
|
|
|
+ v["client_info"] = {k: v for k, v in pairs}
|
|
|
|
|
|
tn.write(b"quit\n")
|
|
|
print("after quit")
|
|
|
print(tn.read_until(b"\n").decode("ascii"))
|
|
|
|
|
|
- import pprint
|
|
|
- pprint.pprint(client_info)
|
|
|
|
|
|
- return client_info
|
|
|
+ users = []
|
|
|
+ for name, info in client_info.items():
|
|
|
+ addl_text = []
|
|
|
+ if info["client_info"].get("client_input_muted", "0") == "1":
|
|
|
+ addl_text.append("Mic muted")
|
|
|
+ if info["client_info"].get("client_output_muted", "0") == "1":
|
|
|
+ addl_text.append("Sound muted")
|
|
|
+ notes = ", ".join(addl_text)
|
|
|
+ users.append(name if len(notes) == 0 else f"{name} ({notes})")
|
|
|
+
|
|
|
+ return users
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
def get_status():
|
|
|
- return jsonify({"users": list(get_users().keys())})
|
|
|
+ return jsonify({"users": get_users})
|
|
|
|
|
|
|
|
|
@app.route("/page")
|
|
|
def get_status_page():
|
|
|
- info = get_users()
|
|
|
- users = list(info.keys())
|
|
|
+ users = get_users()
|
|
|
if len(users) == 0:
|
|
|
text = "No one in teamspeak!"
|
|
|
elif len(users) == 1:
|