mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-23 00:01:45 +00:00
8f424bf0d4
♻️ 重构插件系统 ⚙️ 重写插件 🎨 改进代码结构 📝 完善文档 Co-authored-by: zhxy-CN <admin@owo.cab> Co-authored-by: 洛水居室 <luoshuijs@outlook.com> Co-authored-by: xtaodada <xtao@xtaolink.cn> Co-authored-by: Li Chuangbo <im@chuangbo.li>
31 lines
786 B
Python
31 lines
786 B
Python
from abc import ABC, abstractmethod
|
|
from types import FunctionType
|
|
|
|
from utils.log import logger
|
|
|
|
__all__ = ['Service', 'init_service']
|
|
|
|
|
|
class Service(ABC):
|
|
@abstractmethod
|
|
def __init__(self, *args, **kwargs):
|
|
"""初始化"""
|
|
|
|
async def start(self):
|
|
"""启动 service"""
|
|
|
|
async def stop(self):
|
|
"""关闭 service"""
|
|
|
|
|
|
def init_service(func: FunctionType):
|
|
from core.bot import bot
|
|
if bot.is_running:
|
|
try:
|
|
service = bot.init_inject(func)
|
|
logger.success(f'服务 "{service.__class__.__name__}" 初始化成功')
|
|
bot.add_service(service)
|
|
except Exception as e: # pylint: disable=W0703
|
|
logger.exception(f'来自{func.__module__}的服务初始化失败:{e}')
|
|
return func
|