-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
75 lines (60 loc) · 2.49 KB
/
main.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
import pkgutil
from pathlib import Path
import kayaku
from creart import create
# from graia.amnesia.builtins.uvicorn import UvicornService
from graia.ariadne.app import Ariadne
from graia.ariadne.connection.config import (
HttpClientConfig,
WebsocketClientConfig,
config,
)
from graia.ariadne.model import LogConfig
from graia.saya import Saya
from graiax.playwright import PlaywrightService
kayaku.initialize({"{**}": "./config/{**}"})
from libs import log_level_handler, replace_logger # noqa: E402
from libs.config import basic_cfg, modules_cfg # noqa: E402
# from libs.fastapi_service import FastAPIStarletteService # noqa: E402
from libs.database_services import DatabaseInitService # noqa: E402
from libs.send_action import Safe # noqa: E402
from static.path import modules_path, root_path # noqa: E402
kayaku.bootstrap()
# loop = create(AbstractEventLoop) # 若不需要 loop.run_until_complete(),则不需要此行
# 若 create Saya 则可以省掉 bcc 和 scheduler 的
# sche = create(GraiaScheduler)
# bcc = create(Broadcast)
saya = create(Saya)
Ariadne.options['installed_log'] = True
app = Ariadne(
connection=config(
basic_cfg.miraiApiHttp.account, # 你的机器人的 qq 号
basic_cfg.miraiApiHttp.verifyKey, # 填入 verifyKey
HttpClientConfig(host=basic_cfg.miraiApiHttp.host),
WebsocketClientConfig(host=basic_cfg.miraiApiHttp.host),
),
log_config=LogConfig(log_level_handler),
)
app.default_send_action = Safe
replace_logger(level=0 if basic_cfg.debug else 20, richuru=False)
ignore = ('__init__.py', '__pycache__')
with saya.module_context():
core_modules_path = Path(root_path, 'core_modules')
for module in pkgutil.iter_modules([str(core_modules_path)]):
if module.name in ignore or module.name[0] in ('#', '.', '_'):
continue
saya.require(f'core_modules.{module.name}')
if modules_cfg.enabled:
with saya.module_context():
for module in pkgutil.iter_modules([str(modules_path)]):
if module.name in ignore or module.name[0] in ('#', '.', '_'):
continue
saya.require(f'modules.{module.name}')
if basic_cfg.miraiApiHttp.account == 123456789:
raise ValueError('在?¿ 填一下配置文件?')
app.launch_manager.add_service(DatabaseInitService())
# app.launch_manager.add_service(FastAPIStarletteService())
# app.launch_manager.add_service(UvicornService())
app.launch_manager.add_service(PlaywrightService())
Ariadne.launch_blocking()
kayaku.save_all()