verify contact

This commit is contained in:
Florent de Lamotte 2025-04-17 22:51:37 +02:00
parent 0ee2fdb16a
commit 4324967b2b

View file

@ -427,6 +427,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 2 argnum = 2
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.send_msg(contact, cmds[2]) res = await mc.commands.send_msg(contact, cmds[2])
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -457,6 +463,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 2 argnum = 2
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.send_cmd(contact, cmds[2]) res = await mc.commands.send_cmd(contact, cmds[2])
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -469,6 +481,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 2 argnum = 2
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.send_login(contact, cmds[2]) res = await mc.commands.send_login(contact, cmds[2])
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -517,6 +535,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 2 argnum = 2
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.change_contact_path(contact, cmds[2]) res = await mc.commands.change_contact_path(contact, cmds[2])
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -529,6 +553,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 1 argnum = 1
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.reset_path(contact) res = await mc.commands.reset_path(contact)
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -541,6 +571,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 1 argnum = 1
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.share_contact(contact) res = await mc.commands.share_contact(contact)
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -552,6 +588,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 1 argnum = 1
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.export_contact(contact) res = await mc.commands.export_contact(contact)
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -575,6 +617,12 @@ async def next_cmd(mc, cmds, json_output=False):
argnum = 1 argnum = 1
await mc.ensure_contacts() await mc.ensure_contacts()
contact = mc.get_contact_by_name(cmds[1]) contact = mc.get_contact_by_name(cmds[1])
if contact is None:
if json_output :
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
else:
print(f"Unknown contact {cmds[1]}")
else:
res = await mc.commands.remove_contact(contact) res = await mc.commands.remove_contact(contact)
logger.debug(res) logger.debug(res)
if res.type == EventType.ERROR: if res.type == EventType.ERROR:
@ -665,6 +713,8 @@ async def next_cmd(mc, cmds, json_output=False):
print("Timeout waiting ack") print("Timeout waiting ack")
elif json_output : elif json_output :
print(json.dumps(res.payload, indent=4)) print(json.dumps(res.payload, indent=4))
else :
print("Msg acked")
case "wait_login" | "wl" | "]]": case "wait_login" | "wl" | "]]":
res = await mc.wait_for_event(EventType.LOGIN_SUCCESS) res = await mc.wait_for_event(EventType.LOGIN_SUCCESS)