|
22 | 22 | from prompt_toolkit.formatted_text import ANSI |
23 | 23 | from prompt_toolkit.key_binding import KeyBindings |
24 | 24 | from prompt_toolkit.shortcuts import radiolist_dialog |
25 | | - |
26 | | -#from typing import Iterable, Mapping, Set, Union |
27 | | - |
28 | 25 | from prompt_toolkit.completion.word_completer import WordCompleter |
29 | 26 | from prompt_toolkit.document import Document |
30 | 27 |
|
@@ -316,7 +313,7 @@ def get_completions( self, document, complete_event): |
316 | 313 | opts = [] |
317 | 314 | for k in self.options.keys(): |
318 | 315 | if k[0] == "/" : |
319 | | - v = "/" + k.split("/")[1] + ("/" if k.count("/") == 2 else "") |
| 316 | + v = "/" + k.split("/")[1] #+ ("/" if k.count("/") == 2 else "") |
320 | 317 | if v not in opts: |
321 | 318 | opts.append(v) |
322 | 319 | else: |
@@ -478,6 +475,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None): |
478 | 475 | "change_flags" : None, |
479 | 476 | "req_telemetry" : None, |
480 | 477 | "req_binary" : None, |
| 478 | + "forget_password" : None, |
481 | 479 | } |
482 | 480 |
|
483 | 481 | client_completion_list = dict(contact_completion_list) |
@@ -623,7 +621,6 @@ async def interactive_loop(mc, to=None) : |
623 | 621 | contact = to |
624 | 622 | prev_contact = None |
625 | 623 |
|
626 | | -# await get_contacts(mc, anim=True) |
627 | 624 | await get_contacts(mc, anim=True) |
628 | 625 | await get_channels(mc, anim=True) |
629 | 626 | await subscribe_to_msgs(mc, above=True) |
@@ -889,6 +886,14 @@ async def process_contact_chat_line(mc, contact, line): |
889 | 886 | await process_cmds(mc, args) |
890 | 887 | return True |
891 | 888 |
|
| 889 | + # special case for rp that can be chained from cmdline |
| 890 | + if line.startswith("rp ") or line.startswith("reset_path ") : |
| 891 | + args = ["rp", contact['adv_name']] |
| 892 | + await process_cmds(mc, args) |
| 893 | + secline = line.split(" ", 1)[1] |
| 894 | + await process_contact_chat_line(mc, contact, secline) |
| 895 | + return True |
| 896 | + |
892 | 897 | if line.startswith("set timeout "): |
893 | 898 | cmds=line.split(" ") |
894 | 899 | contact["timeout"] = float(cmds[2]) |
@@ -961,6 +966,38 @@ async def process_contact_chat_line(mc, contact, line): |
961 | 966 | await process_cmds(mc, args) |
962 | 967 | return True |
963 | 968 |
|
| 969 | + if line == "login": # use stored password or prompt for it |
| 970 | + password_file = "" |
| 971 | + password = "" |
| 972 | + if os.path.isdir(MCCLI_CONFIG_DIR) : |
| 973 | + password_file = MCCLI_CONFIG_DIR + contact['adv_name'] + ".pass" |
| 974 | + if os.path.exists(password_file) : |
| 975 | + with open(password_file, "r", encoding="utf-8") as f : |
| 976 | + password=f.readline().strip() |
| 977 | + |
| 978 | + if password == "": |
| 979 | + sess = PromptSession("Password: ", is_password=True) |
| 980 | + password = await sess.prompt_async() |
| 981 | + |
| 982 | + if password_file != "": |
| 983 | + with open(password_file, "w", encoding="utf-8") as f : |
| 984 | + f.write(password) |
| 985 | + |
| 986 | + args = ["login", contact['adv_name'], password] |
| 987 | + await process_cmds(mc, args) |
| 988 | + return True |
| 989 | + |
| 990 | + if line.startswith("forget_password") or line.startswith("fp"): |
| 991 | + password_file = MCCLI_CONFIG_DIR + contact['adv_name'] + ".pass" |
| 992 | + if os.path.exists(password_file): |
| 993 | + os.remove(password_file) |
| 994 | + try: |
| 995 | + secline = line.split(" ", 1)[1] |
| 996 | + await process_contact_chat_line(mc, contact, secline) |
| 997 | + except IndexError: |
| 998 | + pass |
| 999 | + return True |
| 1000 | + |
964 | 1001 | if contact["type"] == 4 and \ |
965 | 1002 | (line.startswith("req_mma ") or line.startswith('rm ')) : |
966 | 1003 | cmds = line.split(" ") |
@@ -1089,6 +1126,9 @@ async def get_channel_by_name (mc, name): |
1089 | 1126 | return None |
1090 | 1127 |
|
1091 | 1128 | async def get_contacts (mc, anim=False, lastomod=0, timeout=5) : |
| 1129 | + if mc._contacts: |
| 1130 | + return |
| 1131 | + |
1092 | 1132 | if anim: |
1093 | 1133 | print("Fetching contacts ", end="", flush=True) |
1094 | 1134 |
|
|
0 commit comments