forked from LWHK/ABot-Graia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (67 loc) · 2.14 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
76
77
78
79
80
81
import os
import asyncio
from pathlib import Path
from loguru import logger
from graia.saya import Saya
from graia.ariadne.app import Ariadne
from graia.broadcast import Broadcast
from graia.scheduler import GraiaScheduler
from graia.ariadne.model import MiraiSession
from graia.ariadne.adapter import DefaultAdapter
from graia.broadcast.interrupt import InterruptControl
from graia.scheduler.saya import GraiaSchedulerBehaviour
from graia.saya.builtins.broadcast import BroadcastBehaviour
from config import yaml_data, save_config
# ANCHOR: Audit debug
# import sys
# def broadcast_audit_hook(ev: str, args: tuple):
# if ev in ("RequirementCrashed", "BroadcastException"):
# logger.error(args[0])
# logger.error(args[1])
# sys.addaudithook(broadcast_audit_hook)
# Finish
LOGPATH = Path("./logs")
LOGPATH.mkdir(exist_ok=True)
logger.add(
LOGPATH.joinpath("latest.log"),
encoding="utf-8",
backtrace=True,
diagnose=True,
rotation="00:00",
retention="30 days",
compression="tar.xz",
colorize=False,
)
logger.info("ABot is starting...")
ignore = ["__init__.py", "__pycache__"]
loop = asyncio.new_event_loop()
bcc = Broadcast(loop=loop)
scheduler = GraiaScheduler(loop, bcc)
inc = InterruptControl(bcc)
app = Ariadne(
broadcast=bcc,
connect_info=DefaultAdapter(
bcc,
MiraiSession(
host=yaml_data["Basic"]["MAH"]["MiraiHost"],
account=yaml_data["Basic"]["MAH"]["BotQQ"],
verify_key=yaml_data["Basic"]["MAH"]["MiraiAuthKey"],
),
),
)
saya = Saya(bcc)
saya.install_behaviours(BroadcastBehaviour(bcc))
saya.install_behaviours(GraiaSchedulerBehaviour(scheduler))
saya.install_behaviours(InterruptControl(bcc))
with saya.module_context():
for module in os.listdir("saya"):
if module in ignore:
continue
if os.path.isdir(module):
saya.require(f"saya.{module}")
else:
saya.require(f"saya.{module.split('.')[0]}")
logger.info("saya加载完成")
if __name__ == "__main__":
app.launch_blocking()
save_config()