This repository has been archived by the owner on Dec 19, 2024. It is now read-only.
forked from GraiaProject/Avilla
-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.py
71 lines (52 loc) · 2.09 KB
/
service.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
from __future__ import annotations
from collections import defaultdict
from typing import TYPE_CHECKING
from launart import Launart, Service
from loguru import logger
from avilla.core.utilles.message_cache import MessageCacheDeque
from avilla.standard.core.application import (
ApplicationClosed,
ApplicationClosing,
ApplicationPreparing,
ApplicationReady,
)
from .graia import AVILLA_ASCII_LOGO, AVILLA_ASCII_RAW_LOGO, log_telemetry
if TYPE_CHECKING:
from .application import Avilla
from .selector import Selector
class AvillaService(Service):
id = "avilla.service"
supported_interface_types = set()
avilla: Avilla
enabled_cache_message: bool
message_cache: defaultdict[Selector, MessageCacheDeque]
def __init__(self, avilla: Avilla, cache_size: int):
self.avilla = avilla
if cache_size > 0:
self.enabled_cache_message = True
self.message_cache = defaultdict(lambda: MessageCacheDeque(cache_size))
super().__init__()
@property
def required(self) -> set[str]:
return set()
@property
def stages(self):
return {"preparing", "blocking", "cleanup"}
def get_interface(self, interface_type):
...
async def launch(self, manager: Launart):
async with self.stage("preparing"):
await self.avilla.broadcast.postEvent(ApplicationPreparing(self.avilla))
logger.info(AVILLA_ASCII_RAW_LOGO, alt=AVILLA_ASCII_LOGO)
log_telemetry()
for protocol in self.avilla.protocols:
logger.info(
f"Using platform: {protocol.__class__}",
# alt=f"[magenta]Using platform: [/][dark_orange]{protocol.__class__.platform}[/]",
)
await self.avilla.broadcast.postEvent(ApplicationReady(self.avilla))
async with self.stage("blocking"):
... # TODO: 先放着.
async with self.stage("cleanup"):
await self.avilla.broadcast.postEvent(ApplicationClosing(self.avilla))
await self.avilla.broadcast.postEvent(ApplicationClosed(self.avilla))