mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-15 00:24:26 +08:00
✨ add color plugin name
This commit is contained in:
parent
aa9abde63a
commit
803b65e08e
@ -15,7 +15,7 @@ from pathlib import Path
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from liteyuki.log import logger
|
from liteyuki.log import logger
|
||||||
from liteyuki.plugin.model import Plugin, PluginMetadata
|
from liteyuki.plugin.model import Plugin, PluginMetadata, PluginType
|
||||||
from liteyuki.utils import path_to_module_name
|
from liteyuki.utils import path_to_module_name
|
||||||
|
|
||||||
_plugins: dict[str, Plugin] = {}
|
_plugins: dict[str, Plugin] = {}
|
||||||
@ -46,9 +46,10 @@ def load_plugin(module_path: str | Path) -> Optional[Plugin]:
|
|||||||
display_name = module.__name__.split(".")[-1]
|
display_name = module.__name__.split(".")[-1]
|
||||||
if module.__dict__.get("__plugin_meta__"):
|
if module.__dict__.get("__plugin_meta__"):
|
||||||
metadata: "PluginMetadata" = module.__dict__["__plugin_meta__"]
|
metadata: "PluginMetadata" = module.__dict__["__plugin_meta__"]
|
||||||
display_name = f"{metadata.name}({module.__name__.split('.')[-1]})"
|
display_name = format_display_name(f"{metadata.name}({module.__name__.split('.')[-1]})", metadata.type)
|
||||||
|
|
||||||
logger.opt(colors=True).success(
|
logger.opt(colors=True).success(
|
||||||
f'Succeeded to load liteyuki plugin "<y>{display_name}</y>"'
|
f'Succeeded to load liteyuki plugin "{display_name}"'
|
||||||
)
|
)
|
||||||
return _plugins[module.__name__]
|
return _plugins[module.__name__]
|
||||||
|
|
||||||
@ -100,3 +101,27 @@ def load_plugins(*plugin_dir: str, ignore_warning: bool = True) -> set[Plugin]:
|
|||||||
if _plugins.get(module_name):
|
if _plugins.get(module_name):
|
||||||
plugins.add(_plugins[module_name])
|
plugins.add(_plugins[module_name])
|
||||||
return plugins
|
return plugins
|
||||||
|
|
||||||
|
|
||||||
|
def format_display_name(display_name: str, plugin_type: PluginType) -> str:
|
||||||
|
"""
|
||||||
|
设置插件名称颜色,根据不同类型插件设置颜色
|
||||||
|
Args:
|
||||||
|
display_name: 插件名称
|
||||||
|
plugin_type: 插件类型
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 设置后的插件名称 <y>name</y>
|
||||||
|
"""
|
||||||
|
color = "y"
|
||||||
|
match plugin_type:
|
||||||
|
case PluginType.APPLICATION:
|
||||||
|
color = "m"
|
||||||
|
case PluginType.IMPLEMENTATION:
|
||||||
|
color = "g"
|
||||||
|
case PluginType.MODULE:
|
||||||
|
color = "e"
|
||||||
|
case PluginType.SERVICE:
|
||||||
|
color = "c"
|
||||||
|
|
||||||
|
return f"<{color}>{display_name} [{plugin_type.name}]</{color}>"
|
||||||
|
@ -59,9 +59,9 @@ class PluginMetadata(BaseModel):
|
|||||||
name: str
|
name: str
|
||||||
description: str = ""
|
description: str = ""
|
||||||
usage: str = ""
|
usage: str = ""
|
||||||
type: str = ""
|
type: PluginType = PluginType.UNCLASSIFIED
|
||||||
author: str = ""
|
author: str = ""
|
||||||
homepage: str = PluginType.UNCLASSIFIED
|
homepage: str = ""
|
||||||
extra: dict[str, Any] = {}
|
extra: dict[str, Any] = {}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,11 +9,12 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
|||||||
@Software: PyCharm
|
@Software: PyCharm
|
||||||
"""
|
"""
|
||||||
from liteyuki import get_config, load_plugin
|
from liteyuki import get_config, load_plugin
|
||||||
from liteyuki.plugin import PluginMetadata, load_plugins
|
from liteyuki.plugin import PluginMetadata, load_plugins, PluginType
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="外部轻雪插件加载器",
|
name="外部轻雪插件加载器",
|
||||||
description="插件加载器,用于加载轻雪原生插件"
|
description="插件加载器,用于加载轻雪原生插件",
|
||||||
|
type=PluginType.SERVICE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,12 +10,13 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
from liteyuki.plugin import PluginMetadata
|
from liteyuki.plugin import PluginMetadata, PluginType
|
||||||
from liteyuki import get_bot, logger
|
from liteyuki import get_bot, logger
|
||||||
from liteyuki.comm.channel import get_channel
|
from liteyuki.comm.channel import get_channel
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="生命周期日志",
|
name="生命周期日志",
|
||||||
|
type=PluginType.SERVICE,
|
||||||
)
|
)
|
||||||
|
|
||||||
bot = get_bot()
|
bot = get_bot()
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
from liteyuki.plugin import PluginMetadata
|
from liteyuki.plugin import PluginMetadata, PluginType
|
||||||
|
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="进程管理器",
|
name="进程管理器",
|
||||||
version="0.1.0",
|
|
||||||
author="snowykami",
|
author="snowykami",
|
||||||
description="进程管理器,用于管理子进程"
|
description="进程管理器,用于管理子进程",
|
||||||
|
type=PluginType.SERVICE
|
||||||
)
|
)
|
@ -8,3 +8,11 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
|||||||
@File : reloader.py.py
|
@File : reloader.py.py
|
||||||
@Software: PyCharm
|
@Software: PyCharm
|
||||||
"""
|
"""
|
||||||
|
from liteyuki.plugin import PluginMetadata, PluginType
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="重启",
|
||||||
|
author="snowykami",
|
||||||
|
description="进程管理器,用于管理子进程",
|
||||||
|
type=PluginType.MODULE
|
||||||
|
)
|
||||||
|
@ -14,11 +14,12 @@ import platform
|
|||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from git import Repo
|
from git import Repo
|
||||||
|
|
||||||
from liteyuki.plugin import PluginMetadata
|
from liteyuki.plugin import PluginMetadata, PluginType
|
||||||
from liteyuki import get_bot, logger
|
from liteyuki import get_bot, logger
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="注册服务",
|
name="注册服务",
|
||||||
|
type=PluginType.SERVICE
|
||||||
)
|
)
|
||||||
|
|
||||||
liteyuki = get_bot()
|
liteyuki = get_bot()
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
from liteyuki.plugin import PluginMetadata, PluginType
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="资源加载器",
|
||||||
|
author="snowykami",
|
||||||
|
description="进程管理器,用于管理子进程",
|
||||||
|
type=PluginType.SERVICE
|
||||||
|
)
|
@ -8,11 +8,12 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
|||||||
@File : __init__.py.py
|
@File : __init__.py.py
|
||||||
@Software: PyCharm
|
@Software: PyCharm
|
||||||
"""
|
"""
|
||||||
from liteyuki.plugin import PluginMetadata
|
from liteyuki.plugin import PluginMetadata, PluginType
|
||||||
|
|
||||||
from .divided_by_lifespan import *
|
from .divided_by_lifespan import *
|
||||||
|
|
||||||
__plugin_mata__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="计划任务",
|
name="计划任务",
|
||||||
description="计划任务插件,一些杂项任务的计划执行。",
|
description="计划任务插件,一些杂项任务的计划执行。",
|
||||||
|
type=PluginType.SERVICE
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user