-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
915e849
commit 3e41304
Showing
10 changed files
with
269 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import json | ||
from prompt_toolkit.completion import NestedCompleter | ||
from settings import CONFIG_DIR, nested_dict_base | ||
|
||
|
||
def get_sub_node_set(): | ||
if not os.path.exists(CONFIG_DIR+'groups.json') or not os.path.exists(CONFIG_DIR+'connections.json'): | ||
return None | ||
with open(CONFIG_DIR+'groups.json') as f: | ||
groups_info = json.load(f) | ||
with open(CONFIG_DIR+'connections.json', encoding='utf-8') as f: | ||
conn = json.load(f) | ||
res = {} | ||
for item in groups_info: | ||
sub_name = groups_info[item]['displayName'].replace(' ', '%20') | ||
connections = [conn[i]['displayName'].replace(' ', '%20') | ||
for i in groups_info[item]['connections']] | ||
|
||
res[sub_name] = set(connections) | ||
return res | ||
|
||
|
||
def generate_completer(): | ||
res = get_sub_node_set() | ||
nested_dict_base['update'] = set(res.keys()) | ||
nested_dict_base['connect'] = res | ||
nested_dict_base['info'] = res | ||
nested_dict_base['delete'] = res | ||
|
||
completer = NestedCompleter.from_nested_dict(nested_dict_base) | ||
|
||
return completer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
from settings import LAST_CONNECT, clean_blocks, load_default_config | ||
|
||
|
||
# port | ||
def port_about(blocks: list): | ||
conf = load_default_config() | ||
blocks = clean_blocks(blocks) | ||
if (not len(blocks)) or len(blocks) > 3 or len(blocks) < 1: | ||
print( | ||
'Error Format,shoould be `port show port` or `port set port [port]`') | ||
return | ||
if blocks[0] == 'show': | ||
print('Http port : %s\nSocks port : %s' % | ||
(conf['http_port'], conf['socks_port'])) | ||
elif blocks[0] == 'set': | ||
http_port = int(input('Please input http port : ')) | ||
socks_port = int(input('Please input socks port : ')) | ||
conf['http_port'] = http_port | ||
conf['socks_port'] = socks_port | ||
with open(LAST_CONNECT, 'w', encoding='utf-8') as f: | ||
f.write(json.dumps(conf, ensure_ascii=False, indent=4)) | ||
|
||
|
||
# path | ||
def path_about(blocks: list): | ||
conf = load_default_config() | ||
blocks = clean_blocks(blocks) | ||
if (not len(blocks)) or len(blocks) > 2 or len(blocks) < 1: | ||
print( | ||
'Error Format,shoould be `path show` or `path set [path]`') | ||
return | ||
if blocks[0] == 'show': | ||
print('Path : %s' % conf['path']) | ||
elif blocks[0] == 'set': | ||
path = input('Please input v2ray path') | ||
conf['path'] = path | ||
with open(LAST_CONNECT, 'w', encoding='utf-8') as f: | ||
f.write(json.dumps(conf, ensure_ascii=False, indent=4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
click==8.0.1 | ||
prompt-toolkit==3.0.19 | ||
urllib3==1.26.6 | ||
wcwidth==0.2.5 |
Oops, something went wrong.