From 49ee83b94d6c6e45390dcfefe9ab4e547da0524f Mon Sep 17 00:00:00 2001 From: Florent Date: Mon, 27 Oct 2025 16:23:53 +0100 Subject: [PATCH] special error treatment for setperm in chat mode --- src/meshcore_cli/meshcore_cli.py | 45 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/meshcore_cli/meshcore_cli.py b/src/meshcore_cli/meshcore_cli.py index 4e40886..098f860 100644 --- a/src/meshcore_cli/meshcore_cli.py +++ b/src/meshcore_cli/meshcore_cli.py @@ -779,28 +779,31 @@ Line starting with \"$\" or \".\" will issue a meshcli command. # special treatment for setperm to support contact name as param elif contact["type"] > 1 and\ (line.startswith("setperm ") or line.startswith("set perm ")): - cmds = shlex.split(line) - off = 1 if line.startswith("set perm") else 0 - name = cmds[1 + off] - perm_string = cmds[2 + off] - if (perm_string.startswith("0x")): - perm = int(perm_string,0) - elif (perm_string.startswith("#")): - perm = int(perm_string[1:]) - else: - perm = int(perm_string,16) - ct=mc.get_contact_by_name(name) - if ct is None: - ct=mc.get_contact_by_key_prefix(name) - if ct is None: - if name == "self" or mc.self_info["public_key"].startswith(name): - key = mc.self_info["public_key"] + try: + cmds = shlex.split(line) + off = 1 if line.startswith("set perm") else 0 + name = cmds[1 + off] + perm_string = cmds[2 + off] + if (perm_string.startswith("0x")): + perm = int(perm_string,0) + elif (perm_string.startswith("#")): + perm = int(perm_string[1:]) else: - key = name - else: - key=ct["public_key"] - newline=f"setperm {key} {perm}" - await process_cmds(mc, ["cmd", contact["adv_name"], newline]) + perm = int(perm_string,16) + ct=mc.get_contact_by_name(name) + if ct is None: + ct=mc.get_contact_by_key_prefix(name) + if ct is None: + if name == "self" or mc.self_info["public_key"].startswith(name): + key = mc.self_info["public_key"] + else: + key = name + else: + key=ct["public_key"] + newline=f"setperm {key} {perm}" + await process_cmds(mc, ["cmd", contact["adv_name"], newline]) + except IndexError: + print("Wrong number of parameters") # same but for commands with a parameter elif contact["type"] > 0 and (line.startswith("cmd ") or\