@@ -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