-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathconfig.py
71 lines (56 loc) · 2.66 KB
/
config.py
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
import os
import yaml
import json
from graia.application import GraiaMiraiApplication
from graia.application.event.messages import Group
from graia.application.message.elements.internal import MessageChain, Plain
class NoAliasDumper(yaml.SafeDumper):
def ignore_aliases(self, data):
return True
async def sendmsg(app: GraiaMiraiApplication, group: Group):
await app.sendGroupMessage(group, MessageChain.create([Plain("该功能暂不开启")]))
if not os.path.exists('config.yaml') and os.path.exists('config.exp.yaml'):
print('请修改 config.exp.yaml 并重命名为 config.yaml !')
print('请修改 config.exp.yaml 并重命名为 config.yaml !')
print('请修改 config.exp.yaml 并重命名为 config.yaml !')
exit()
elif not os.path.exists('config.yaml') and not os.path.exists('config.exp.yaml'):
print('在?宁的配置文件呢?¿?¿')
exit()
with open('config.yaml', 'r', encoding="utf-8") as f:
file_data = f.read()
yaml_data = yaml.load(file_data, Loader=yaml.FullLoader)
if os.path.exists('groupdata.yaml'):
with open('groupdata.yaml', 'r', encoding="utf-8") as f:
file_data = f.read()
group_data = yaml.load(file_data, Loader=yaml.FullLoader)
else:
with open('groupdata.yaml', 'w', encoding="utf-8") as f:
pass
group_data = json.loads("{}")
if os.path.exists('grouplist.yaml'):
with open('grouplist.yaml', 'r', encoding="utf-8") as f:
file_data = f.read()
group_list = yaml.load(file_data, Loader=yaml.FullLoader)
else:
with open('grouplist.yaml', 'w', encoding="utf-8") as f:
group_list = {
"white": [1]
}
yaml.dump(group_list, f, allow_unicode=True, Dumper=NoAliasDumper)
if not bool(yaml_data['Final']):
print("配置文件未修改完成,请手动编辑 config.exp.ymal 进行修改并重命名为 config.yaml")
exit()
if yaml_data['Basic']['Permission']['Master'] not in yaml_data['Basic']['Permission']['Admin']:
yaml_data['Basic']['Permission']['Admin'].append(yaml_data['Basic']['Permission']['Master'])
with open("config.yaml", 'w', encoding="utf-8") as f:
yaml.dump(yaml_data, f, allow_unicode=True)
print("管理员内未包含主人,已自动添加")
def save_config():
print("正在保存配置文件")
with open("groupdata.yaml", 'w', encoding="utf-8") as f:
yaml.dump(group_data, f, allow_unicode=True, Dumper=NoAliasDumper)
with open("config.yaml", 'w', encoding="utf-8") as f:
yaml.dump(yaml_data, f, allow_unicode=True, Dumper=NoAliasDumper)
with open("grouplist.yaml", 'w', encoding="utf-8") as f:
yaml.dump(group_list, f, allow_unicode=True, Dumper=NoAliasDumper)