|
@@ -50,13 +50,30 @@ def login(tn, username, password):
|
|
|
print("----")
|
|
|
|
|
|
|
|
|
+def get_client_info(tn):
|
|
|
+ tn.write(b"clientlist\n")
|
|
|
+ response = tn.read_until(b"\n").decode("utf-8")
|
|
|
+ print("after clientlist")
|
|
|
+ print(response)
|
|
|
+ print(tn.read_until(b"\n").decode("utf-8"))
|
|
|
+ print("----")
|
|
|
+
|
|
|
+ entry_maps = parse_ts_response(response)
|
|
|
+ # combine the maps into one large map, ignoring serveradmin query user
|
|
|
+ return {info["client_nickname"]: info for info in entry_maps if "serveradmin" not in info["client_nickname"]}
|
|
|
+
|
|
|
+
|
|
|
def post_to_channel(host, port, username, password, message):
|
|
|
message_santized = message.strip().replace(" ", r"\s")
|
|
|
- message_command = f"sendtextmessage targetmode=2 msg={message_santized}\n".encode("utf-8")
|
|
|
print(message_command.decode("utf-8"))
|
|
|
with Telnet(host, port, 5) as tn:
|
|
|
login(tn, username, password)
|
|
|
- tn.write(message_command)
|
|
|
+
|
|
|
+ client_info = get_client_info(tn)
|
|
|
+ audiobot_id = client_info["AudioBot"]["clid"]
|
|
|
+
|
|
|
+ tn.write(f"sendtextmessage targetmode=1 target={audiobot_id} msg={message_santized}\n".encode("utf-8"))
|
|
|
+ # tn.write(f"sendtextmessage targetmode=1 target={audiobot_id} msg=!clear\n".encode("utf-8"))
|
|
|
tn.write(b"quit\n")
|
|
|
|
|
|
|
|
@@ -75,16 +92,7 @@ def query_ts(host, port, username, password):
|
|
|
# rearrange the maps into one large channel lookup map
|
|
|
channels = {info["cid"]: info["channel_name"].replace(r"\s", " ") for info in channel_maps}
|
|
|
|
|
|
- tn.write(b"clientlist\n")
|
|
|
- response = tn.read_until(b"\n").decode("utf-8")
|
|
|
- print("after clientlist")
|
|
|
- print(response)
|
|
|
- print(tn.read_until(b"\n").decode("utf-8"))
|
|
|
- print("----")
|
|
|
-
|
|
|
- entry_maps = parse_ts_response(response)
|
|
|
- # 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"]}
|
|
|
+ client_info = get_client_info(tn)
|
|
|
|
|
|
for k, v in client_info.items():
|
|
|
tn.write(f"clientinfo clid={v['clid']}\n".encode("utf-8"))
|