mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
change behavior of /to
This commit is contained in:
parent
ae10bb701a
commit
72a16dfd36
1 changed files with 50 additions and 51 deletions
|
|
@ -539,6 +539,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
|
||||||
|
|
||||||
completion_list = {
|
completion_list = {
|
||||||
"to" : to_list,
|
"to" : to_list,
|
||||||
|
"/to" : to_list,
|
||||||
"public" : None,
|
"public" : None,
|
||||||
"chan" : None,
|
"chan" : None,
|
||||||
}
|
}
|
||||||
|
|
@ -859,8 +860,6 @@ Some cmds have an help accessible with ?<cmd>. Do ?[Tab] to get a list.
|
||||||
|
|
||||||
await subscribe_to_msgs(mc, above=True)
|
await subscribe_to_msgs(mc, above=True)
|
||||||
|
|
||||||
handle_new_contact.print_new_contacts = True
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if os.path.isdir(MCCLI_CONFIG_DIR) :
|
if os.path.isdir(MCCLI_CONFIG_DIR) :
|
||||||
our_history = FileHistory(MCCLI_HISTORY_FILE)
|
our_history = FileHistory(MCCLI_HISTORY_FILE)
|
||||||
|
|
@ -1000,6 +999,9 @@ Some cmds have an help accessible with ?<cmd>. Do ?[Tab] to get a list.
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print(scope)
|
print(scope)
|
||||||
|
|
||||||
|
elif line == "quit" or line == "q" or line == "/quit" or line == "/q" :
|
||||||
|
break
|
||||||
|
|
||||||
elif contact is None and (line.startswith("apply_to ") or line.startswith("at ")) or\
|
elif contact is None and (line.startswith("apply_to ") or line.startswith("at ")) or\
|
||||||
line.startswith("/apply_to ") or line.startswith("/at ") :
|
line.startswith("/apply_to ") or line.startswith("/at ") :
|
||||||
try:
|
try:
|
||||||
|
|
@ -1007,52 +1009,8 @@ Some cmds have an help accessible with ?<cmd>. Do ?[Tab] to get a list.
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error(f"Error with apply_to command parameters")
|
logger.error(f"Error with apply_to command parameters")
|
||||||
|
|
||||||
elif line.startswith("/") :
|
elif line.startswith("to ") or line.startswith("/to "): # dest
|
||||||
path = line.split(" ", 1)[0]
|
dest = line.split(" ", 1)[1]
|
||||||
if path.count("/") == 1:
|
|
||||||
args = line[1:].split(" ")
|
|
||||||
dest = args[0]
|
|
||||||
dest_scope = None
|
|
||||||
if "%" in dest :
|
|
||||||
dest_scope = dest.split("%")[-1]
|
|
||||||
dest = dest[:-len(dest_scope)-1]
|
|
||||||
await set_scope (mc, dest_scope)
|
|
||||||
tct = mc.get_contact_by_name(dest)
|
|
||||||
if len(args)>1 and not tct is None: # a contact, send a message
|
|
||||||
if tct["type"] == 1 or tct["type"] == 3: # client or room
|
|
||||||
last_ack = await msg_ack(mc, tct, line.split(" ", 1)[1])
|
|
||||||
else:
|
|
||||||
print("Can only send msg to chan, client or room")
|
|
||||||
else :
|
|
||||||
ch = await get_channel_by_name(mc, dest)
|
|
||||||
if len(args)>1 and not ch is None: # a channel, send message
|
|
||||||
await send_chan_msg(mc, ch["channel_idx"], line.split(" ", 1)[1])
|
|
||||||
else :
|
|
||||||
try :
|
|
||||||
await process_cmds(mc, shlex.split(line[1:]))
|
|
||||||
except ValueError:
|
|
||||||
logger.error(f"Error processing line{line[1:]}")
|
|
||||||
else:
|
|
||||||
cmdline = line[1:].split("/",1)[1]
|
|
||||||
contact_name = path[1:].split("/",1)[0]
|
|
||||||
dest_scope = None
|
|
||||||
if "%" in contact_name:
|
|
||||||
dest_scope = contact_name.split("%")[-1]
|
|
||||||
contact_name = contact_name[:-len(dest_scope)-1]
|
|
||||||
await set_scope (mc, dest_scope)
|
|
||||||
tct = mc.get_contact_by_name(contact_name)
|
|
||||||
if tct is None:
|
|
||||||
print(f"{contact_name} is not a contact")
|
|
||||||
else:
|
|
||||||
if not await process_contact_chat_line(mc, tct, cmdline):
|
|
||||||
if cmdline != "":
|
|
||||||
if tct["type"] == 1:
|
|
||||||
last_ack = await msg_ack(mc, tct, cmdline)
|
|
||||||
else :
|
|
||||||
await process_cmds(mc, ["cmd", tct["adv_name"], cmdline])
|
|
||||||
|
|
||||||
elif line.startswith("to ") : # dest
|
|
||||||
dest = line[3:]
|
|
||||||
if dest.startswith("\"") or dest.startswith("\'") : # if name starts with a quote
|
if dest.startswith("\"") or dest.startswith("\'") : # if name starts with a quote
|
||||||
dest = shlex.split(dest)[0] # use shlex.split to get contact name between quotes
|
dest = shlex.split(dest)[0] # use shlex.split to get contact name between quotes
|
||||||
dest_scope = None
|
dest_scope = None
|
||||||
|
|
@ -1098,14 +1056,55 @@ Some cmds have an help accessible with ?<cmd>. Do ?[Tab] to get a list.
|
||||||
if not dest_scope is None:
|
if not dest_scope is None:
|
||||||
scope = await set_scope(mc, dest_scope)
|
scope = await set_scope(mc, dest_scope)
|
||||||
|
|
||||||
elif line == "to" :
|
elif line == "to" or line == "/to" :
|
||||||
if contact is None :
|
if contact is None :
|
||||||
print(mc.self_info['name'])
|
print(mc.self_info['name'])
|
||||||
else:
|
else:
|
||||||
print(contact["adv_name"])
|
print(contact["adv_name"])
|
||||||
|
|
||||||
elif line == "quit" or line == "q" :
|
elif line.startswith("/") :
|
||||||
break
|
path = line.split(" ", 1)[0]
|
||||||
|
if path.count("/") == 1:
|
||||||
|
args = line[1:].split(" ")
|
||||||
|
dest = args[0]
|
||||||
|
dest_scope = None
|
||||||
|
if "%" in dest :
|
||||||
|
dest_scope = dest.split("%")[-1]
|
||||||
|
dest = dest[:-len(dest_scope)-1]
|
||||||
|
await set_scope (mc, dest_scope)
|
||||||
|
tct = mc.get_contact_by_name(dest)
|
||||||
|
if len(args)>1 and not tct is None: # a contact, send a message
|
||||||
|
if tct["type"] == 1 or tct["type"] == 3: # client or room
|
||||||
|
last_ack = await msg_ack(mc, tct, line.split(" ", 1)[1])
|
||||||
|
else:
|
||||||
|
print("Can only send msg to chan, client or room")
|
||||||
|
else :
|
||||||
|
ch = await get_channel_by_name(mc, dest)
|
||||||
|
if len(args)>1 and not ch is None: # a channel, send message
|
||||||
|
await send_chan_msg(mc, ch["channel_idx"], line.split(" ", 1)[1])
|
||||||
|
else :
|
||||||
|
try :
|
||||||
|
await process_cmds(mc, shlex.split(line[1:]))
|
||||||
|
except ValueError:
|
||||||
|
logger.error(f"Error processing line{line[1:]}")
|
||||||
|
else:
|
||||||
|
cmdline = line[1:].split("/",1)[1]
|
||||||
|
contact_name = path[1:].split("/",1)[0]
|
||||||
|
dest_scope = None
|
||||||
|
if "%" in contact_name:
|
||||||
|
dest_scope = contact_name.split("%")[-1]
|
||||||
|
contact_name = contact_name[:-len(dest_scope)-1]
|
||||||
|
await set_scope (mc, dest_scope)
|
||||||
|
tct = mc.get_contact_by_name(contact_name)
|
||||||
|
if tct is None:
|
||||||
|
print(f"{contact_name} is not a contact")
|
||||||
|
else:
|
||||||
|
if not await process_contact_chat_line(mc, tct, cmdline):
|
||||||
|
if cmdline != "":
|
||||||
|
if tct["type"] == 1:
|
||||||
|
last_ack = await msg_ack(mc, tct, cmdline)
|
||||||
|
else :
|
||||||
|
await process_cmds(mc, ["cmd", tct["adv_name"], cmdline])
|
||||||
|
|
||||||
# commands that take one parameter (don't need quotes)
|
# commands that take one parameter (don't need quotes)
|
||||||
elif line.startswith("public ") :
|
elif line.startswith("public ") :
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue