2024-07-25 01:58:21 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""
|
2024-08-12 11:44:30 +08:00
|
|
|
|
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
2024-07-25 01:58:21 +08:00
|
|
|
|
|
|
|
|
|
@Time : 2024/7/24 上午12:02
|
|
|
|
|
@Author : snowykami
|
|
|
|
|
@Email : snowykami@outlook.com
|
|
|
|
|
@File : model.py
|
|
|
|
|
@Software: PyCharm
|
|
|
|
|
"""
|
2024-10-06 02:39:10 +08:00
|
|
|
|
from enum import Enum
|
2024-07-25 01:58:21 +08:00
|
|
|
|
from types import ModuleType
|
2024-10-06 02:39:10 +08:00
|
|
|
|
from typing import Any, Optional
|
2024-07-25 01:58:21 +08:00
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
2024-10-06 02:39:10 +08:00
|
|
|
|
class PluginType(Enum):
|
|
|
|
|
"""
|
|
|
|
|
插件类型枚举值
|
|
|
|
|
"""
|
|
|
|
|
APPLICATION = "application"
|
|
|
|
|
"""应用端:例如NoneBot"""
|
|
|
|
|
|
|
|
|
|
SERVICE = "service"
|
|
|
|
|
"""服务端:例如AI绘画后端"""
|
|
|
|
|
|
|
|
|
|
MODULE = "module"
|
|
|
|
|
"""模块:导出对象给其他插件使用"""
|
|
|
|
|
|
|
|
|
|
UNCLASSIFIED = "unclassified"
|
|
|
|
|
"""未分类:默认值"""
|
|
|
|
|
|
|
|
|
|
TEST = "test"
|
|
|
|
|
"""测试:测试插件"""
|
|
|
|
|
|
|
|
|
|
|
2024-07-25 01:58:21 +08:00
|
|
|
|
class PluginMetadata(BaseModel):
|
|
|
|
|
"""
|
2024-08-12 11:44:30 +08:00
|
|
|
|
轻雪插件元数据,由插件编写者提供,name为必填项
|
2024-10-06 02:39:10 +08:00
|
|
|
|
Attributes:
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
|
|
name: str
|
|
|
|
|
插件名称
|
|
|
|
|
description: str
|
|
|
|
|
插件描述
|
|
|
|
|
usage: str
|
|
|
|
|
插件使用方法
|
|
|
|
|
type: str
|
|
|
|
|
插件类型
|
|
|
|
|
author: str
|
|
|
|
|
插件作者
|
|
|
|
|
homepage: str
|
|
|
|
|
插件主页
|
|
|
|
|
extra: dict[str, Any]
|
|
|
|
|
额外信息
|
2024-07-25 01:58:21 +08:00
|
|
|
|
"""
|
|
|
|
|
name: str
|
2024-08-12 11:44:30 +08:00
|
|
|
|
description: str = ""
|
2024-07-25 01:58:21 +08:00
|
|
|
|
usage: str = ""
|
2024-10-06 02:39:10 +08:00
|
|
|
|
type: PluginType = PluginType.UNCLASSIFIED
|
|
|
|
|
author: str = ""
|
2024-07-25 01:58:21 +08:00
|
|
|
|
homepage: str = ""
|
2024-10-06 02:39:10 +08:00
|
|
|
|
extra: dict[str, Any] = {}
|
2024-07-25 01:58:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Plugin(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
存储插件信息
|
|
|
|
|
"""
|
|
|
|
|
model_config = {
|
|
|
|
|
'arbitrary_types_allowed': True
|
|
|
|
|
}
|
|
|
|
|
name: str
|
|
|
|
|
"""插件名称 例如plugin_loader"""
|
|
|
|
|
module: ModuleType
|
|
|
|
|
"""插件模块对象"""
|
|
|
|
|
module_name: str
|
|
|
|
|
"""点分割模块路径 例如a.b.c"""
|
|
|
|
|
metadata: Optional[PluginMetadata] = None
|
|
|
|
|
|
|
|
|
|
def __hash__(self):
|
|
|
|
|
return hash(self.module_name)
|