File size: 2,341 Bytes
33d4059
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
import os
import hashlib

if __name__ == "__main__":
    config = None
    path = os.path.dirname(os.path.realpath(__file__))
    os.chdir(path)
    if os.path.exists("config.json"):
        with open("config.json", "r") as f:
            config = json.load(f)
            try:
                config["config"]
            except KeyError:
                config = None
    if config is None:
        print(f"配置文件不存在或为空,创建新配置...")
        config = {"config": []}
        print(f"输入会话ID: ")
        user_data = {"conversation_id": input()}
        print(f"输入cookies: ")
        user_data["cookies"] = input()
        config["config"].append(user_data)
    
    again = True
    while True:
        if again:
            num = len(config["config"])
            print(f"\n当前有 {num} 个配置。")
        print("----------")
        print(f"1. 添加新配置")
        print(f"2. 删除所有配置")
        print(f"3. 设置密码")
        print(f"4. 保存并退出")
        choice = input()
        
        if choice == "1":
            print(f"输入会话ID: ")
            user_data = {"conversation_id": input()}
            print(f"输入cookies: ")
            user_data["cookies"] = input()
            config["config"].append(user_data)
            print("\n成功添加配置!")
            again = True
        
        elif choice == "2":
            print("确定要删除所有配置吗? (y/n)")
            if input().lower() == 'y':
                config["config"] = []
                print("已删除所有配置")
            again = True
        
        elif choice == "3":
            print(f"输入新密码(留空则删除密码): ")
            password = input()
            with open("password.txt", "w") as f:
                if password != "":
                    f.write(hashlib.sha256(password.encode()).hexdigest())
                    print(f"密码已设置")
                else:
                    f.write("")
                    print(f"密码已删除")
        
        elif choice == "4":
            with open("config.json", "w") as f:
                json.dump(config, f, indent=4)
            print("配置已保存")
            break
        
        else:
            print(f"无效的选择")
            again = False