2024-03-18 18:21:56 +08:00
|
|
|
import nonebot.plugin
|
|
|
|
from nonebot import on_command
|
2024-03-19 00:27:40 +08:00
|
|
|
from nonebot.permission import SUPERUSER
|
|
|
|
|
2024-03-20 22:30:52 +08:00
|
|
|
from src.utils.message import button, send_markdown
|
2024-03-20 18:27:49 +08:00
|
|
|
from src.utils.typing import T_Bot, T_MessageEvent
|
2024-03-18 18:21:56 +08:00
|
|
|
from src.utils.language import get_user_lang
|
|
|
|
|
2024-03-21 01:20:18 +08:00
|
|
|
list_plugins = on_command("list-plugin", aliases={"列出插件", "插件列表"}, priority=0, permission=SUPERUSER)
|
2024-03-20 18:27:49 +08:00
|
|
|
toggle_plugin = on_command("enable-plugin", aliases={"启用插件", "禁用插件", "disable-plugin"}, priority=0, permission=SUPERUSER)
|
2024-03-18 18:21:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
@list_plugins.handle()
|
2024-03-20 18:27:49 +08:00
|
|
|
async def _(event: T_MessageEvent, bot: T_Bot):
|
2024-03-19 00:27:40 +08:00
|
|
|
lang = get_user_lang(str(event.user_id))
|
2024-03-20 18:27:49 +08:00
|
|
|
reply = f"# {lang.get('npm.loaded_plugins')} | {lang.get('npm.total', TOTAL=len(nonebot.get_loaded_plugins()))} \n***"
|
2024-03-18 18:21:56 +08:00
|
|
|
for plugin in nonebot.get_loaded_plugins():
|
2024-03-19 00:27:40 +08:00
|
|
|
# 检查是否有 metadata 属性
|
|
|
|
if plugin.metadata:
|
2024-03-21 01:20:18 +08:00
|
|
|
reply += (f"\n{button(lang.get('npm.help'), 'help %s' % plugin.name, False, False)} "
|
|
|
|
f"**{plugin.metadata.name}**\n"
|
2024-03-20 22:30:52 +08:00
|
|
|
f"\n > {plugin.metadata.description}\n\n***\n")
|
2024-03-19 00:27:40 +08:00
|
|
|
else:
|
2024-03-21 01:20:18 +08:00
|
|
|
reply += (f"\n{button(lang.get('npm.help'), 'help %s' % plugin.name, False, False)} "
|
|
|
|
f"**{plugin.name}**\n"
|
2024-03-20 22:30:52 +08:00
|
|
|
f"\n > {lang.get('npm.no_description')}\n\n***\n")
|
2024-03-20 18:27:49 +08:00
|
|
|
await send_markdown(reply, bot, event=event)
|