Skip to content

Commit 49ee83b

Browse files
committed
special error treatment for setperm in chat mode
1 parent 3839ad8 commit 49ee83b

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/meshcore_cli/meshcore_cli.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -779,28 +779,31 @@ def _(event):
779779
# special treatment for setperm to support contact name as param
780780
elif contact["type"] > 1 and\
781781
(line.startswith("setperm ") or line.startswith("set perm ")):
782-
cmds = shlex.split(line)
783-
off = 1 if line.startswith("set perm") else 0
784-
name = cmds[1 + off]
785-
perm_string = cmds[2 + off]
786-
if (perm_string.startswith("0x")):
787-
perm = int(perm_string,0)
788-
elif (perm_string.startswith("#")):
789-
perm = int(perm_string[1:])
790-
else:
791-
perm = int(perm_string,16)
792-
ct=mc.get_contact_by_name(name)
793-
if ct is None:
794-
ct=mc.get_contact_by_key_prefix(name)
795-
if ct is None:
796-
if name == "self" or mc.self_info["public_key"].startswith(name):
797-
key = mc.self_info["public_key"]
782+
try:
783+
cmds = shlex.split(line)
784+
off = 1 if line.startswith("set perm") else 0
785+
name = cmds[1 + off]
786+
perm_string = cmds[2 + off]
787+
if (perm_string.startswith("0x")):
788+
perm = int(perm_string,0)
789+
elif (perm_string.startswith("#")):
790+
perm = int(perm_string[1:])
798791
else:
799-
key = name
800-
else:
801-
key=ct["public_key"]
802-
newline=f"setperm {key} {perm}"
803-
await process_cmds(mc, ["cmd", contact["adv_name"], newline])
792+
perm = int(perm_string,16)
793+
ct=mc.get_contact_by_name(name)
794+
if ct is None:
795+
ct=mc.get_contact_by_key_prefix(name)
796+
if ct is None:
797+
if name == "self" or mc.self_info["public_key"].startswith(name):
798+
key = mc.self_info["public_key"]
799+
else:
800+
key = name
801+
else:
802+
key=ct["public_key"]
803+
newline=f"setperm {key} {perm}"
804+
await process_cmds(mc, ["cmd", contact["adv_name"], newline])
805+
except IndexError:
806+
print("Wrong number of parameters")
804807

805808
# same but for commands with a parameter
806809
elif contact["type"] > 0 and (line.startswith("cmd ") or\

0 commit comments

Comments
 (0)