-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.py
executable file
·74 lines (59 loc) · 2.07 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
#!/usr/bin/env python
import contextlib
from pathlib import Path
from graia.ariadne.app import Ariadne
from graia.ariadne.event.lifecycle import ApplicationLaunched, ApplicationShutdowned
from graia.ariadne.event.message import FriendMessage, GroupMessage
from graia.ariadne.message.chain import MessageChain
from graia.ariadne.message.element import Source
from graia.ariadne.model import Friend, Group, Member
from loguru import logger
from app.core.app import AppCore
from app.core.commander import CommandDelegateManager
from app.core.controller import Controller
from app.extend.message_queue import mq
from app.util.exceptions.depend import DependError
from app.util.other import offline_notice, online_notice
from app.util.version import version_notice
LOG_PATH = Path(__file__).parent.joinpath("app/tmp/logs")
LOG_PATH.mkdir(parents=True, exist_ok=True)
logger.add(
LOG_PATH.joinpath("common.log"),
level="INFO",
rotation="2 days",
retention="10 days",
compression="zip",
encoding="utf-8",
)
logger.add(
LOG_PATH.joinpath("error.log"),
level="ERROR",
rotation="6 days",
retention="30 days",
compression="zip",
encoding="utf-8",
)
core = AppCore()
bcc = core.get_bcc()
inc = core.get_inc()
manager = CommandDelegateManager()
@bcc.receiver(FriendMessage)
async def friend_message_handler(app: Ariadne, message: MessageChain, friend: Friend, source: Source):
with contextlib.suppress(DependError):
await Controller(app, message, friend, source, inc, manager).process_event()
@bcc.receiver(GroupMessage)
async def group_message_handler(app: Ariadne, message: MessageChain, group: Group, member: Member, source: Source):
with contextlib.suppress(DependError):
await Controller(app, message, group, member, source, inc, manager).process_event()
@logger.catch
@bcc.receiver(ApplicationLaunched)
async def init():
await core.bot_launch_init()
await online_notice()
await version_notice()
@logger.catch
@bcc.receiver(ApplicationShutdowned)
async def stop():
await offline_notice()
await mq.stop()
core.launch()