mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
Change contract for commands to return full event
This commit is contained in:
parent
39ea3cb3f3
commit
6fbf15885d
17 changed files with 231 additions and 104 deletions
|
|
@ -17,7 +17,9 @@ async def handle_message(event):
|
|||
data = event.payload
|
||||
|
||||
contact = mc.get_contact_by_key_prefix(data['pubkey_prefix'])
|
||||
|
||||
if contact is None:
|
||||
print(f"Unknown contact with pubkey prefix: {data['pubkey_prefix']}")
|
||||
return
|
||||
print(f"{contact['adv_name']}: {data['text']}")
|
||||
|
||||
async def main () :
|
||||
|
|
@ -54,7 +56,7 @@ async def main () :
|
|||
if line.startswith("to ") :
|
||||
dest = line[3:]
|
||||
nc = mc.get_contact_by_name(dest)
|
||||
if mc is None:
|
||||
if nc is None:
|
||||
print(f"Contact '{DEST}' not found in contacts.")
|
||||
return
|
||||
else :
|
||||
|
|
@ -72,8 +74,12 @@ async def main () :
|
|||
else :
|
||||
if line.startswith("send") :
|
||||
line = line[5:]
|
||||
ret = await mc.commands.send_msg(contact , line)
|
||||
exp_ack = ret["expected_ack"].hex()
|
||||
result = await mc.commands.send_msg(contact, line)
|
||||
if result.type == EventType.ERROR:
|
||||
print(f"⚠️ Failed to send message: {result.payload}")
|
||||
continue
|
||||
|
||||
exp_ack = result.payload["expected_ack"].hex()
|
||||
print(" Sent ... ", end="", flush=True)
|
||||
res = await mc.wait_for_event(EventType.ACK, attribute_filters={"code": exp_ack}, timeout=5)
|
||||
if res is None :
|
||||
|
|
@ -82,7 +88,7 @@ async def main () :
|
|||
print ("Ack")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
meshcore.stop()
|
||||
mc.stop()
|
||||
print("\nExiting...")
|
||||
except asyncio.CancelledError:
|
||||
# Handle task cancellation from KeyboardInterrupt in asyncio.run()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue