forked from HornCopper/Inkar-Suki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
82 lines (70 loc) · 2.19 KB
/
bot.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
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from src.tools.config import Config
import os
from nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter
from src.tools.dep.bot import *
botpy = os.getcwd()
tools_path = botpy + "/src/tools"
print(tools_path)
def check_folder(path: str, can_retry: bool = True):
if os.path.isdir(path):
return True
if os.path.exists(path):
logger.logger.warn(f"{path}被文件占用,将其强行移除。")
os.remove(path)
if not can_retry:
return False
return check_folder(path, can_retry=False)
os.mkdir(path)
return True
def check_folders(folder_nest: dict, parent_path: str = None):
if not parent_path:
parent_path = ""
else:
parent_path = f"{parent_path}{os.sep}"
logger.info(f"初始化系统文件夹:{parent_path}")
for f in folder_nest:
new_parent = f"{parent_path}{f}"
check_folder(new_parent)
children = folder_nest[f]
if isinstance(children, dict):
check_folders(children, new_parent)
init_folders = {
"./src": {
"data": None,
"cache": None,
"sign": None,
"assets": {
"jx3": {
"skills": None,
"icons": None,
"achievement": None,
"talents": None,
"adventure": None,
"serendipity": None,
"pvx": {
"flower": None
}
}
},
"plugins": None
}
}
check_folders(init_folders)
plugins = os.listdir("./src/plugins")
for i in plugins:
if not os.path.exists(f"./src/plugins/{i}/info.json"):
raise FileNotFoundError(
f"Plugin `{i}` required a `info.json` but not found. Please check and try again.")
sys.exit(1)
nonebot.init(tools_path=tools_path, log_level="INFO")
app = nonebot.get_asgi()
driver = nonebot.get_driver()
driver.register_adapter(ONEBOT_V11Adapter)
nonebot.load_from_toml("pyproject.toml")
if __name__ == "__main__":
nonebot.logger.warning(
"Always use `nb run` to start the bot instead of manually running!")
nonebot.run(app="__mp_main__:app")