forked from bot/app
fix: 插件列表显示错误问题
This commit is contained in:
@ -7,7 +7,7 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
|
||||
from src.utils.message import send_markdown
|
||||
from src.utils.typing import T_Message, T_Bot, v11, T_MessageEvent
|
||||
from src.utils.ly_typing import T_Message, T_Bot, v11, T_MessageEvent
|
||||
|
||||
md_test = on_command("mdts", aliases={"会话md"}, permission=SUPERUSER)
|
||||
md_group = on_command("mdg", aliases={"群md"}, permission=SUPERUSER)
|
||||
|
@ -7,7 +7,7 @@ from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_alconna import on_alconna
|
||||
from src.utils.data import LiteModel
|
||||
from src.utils.message import send_markdown
|
||||
from src.utils.typing import T_Bot, T_MessageEvent
|
||||
from src.utils.ly_typing import T_Bot, T_MessageEvent
|
||||
from src.utils.data import Database
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@ import nonebot.plugin
|
||||
|
||||
from src.utils.data import Database, LiteModel
|
||||
from src.utils.data_manager import GroupChat, InstalledPlugin, User, group_db, plugin_db, user_db
|
||||
from src.utils.typing import T_MessageEvent
|
||||
from src.utils.ly_typing import T_MessageEvent
|
||||
|
||||
LNPM_COMMAND_START = "lnpm"
|
||||
|
||||
|
@ -1,11 +1,7 @@
|
||||
import json
|
||||
import os.path
|
||||
import shutil
|
||||
import sys
|
||||
from io import StringIO
|
||||
from typing import Optional
|
||||
|
||||
import aiofiles
|
||||
import aiohttp
|
||||
import nonebot
|
||||
import pip
|
||||
@ -14,11 +10,9 @@ from nonebot.permission import SUPERUSER
|
||||
from nonebot_plugin_alconna import Alconna, Args, Subcommand, on_alconna
|
||||
|
||||
from src.utils.language import get_user_lang
|
||||
from src.utils.ly_typing import T_Bot
|
||||
from src.utils.message import Markdown as md, send_markdown
|
||||
from src.utils.resource import get_res
|
||||
from src.utils.typing import T_Bot, T_MessageEvent
|
||||
from .common import *
|
||||
from src.utils.data_manager import InstalledPlugin
|
||||
|
||||
npm_alc = on_alconna(
|
||||
Alconna(
|
||||
@ -38,7 +32,7 @@ npm_alc = on_alconna(
|
||||
alias=["i", "安装"],
|
||||
),
|
||||
Subcommand(
|
||||
"remove",
|
||||
"uninstall",
|
||||
Args["plugin_name", str],
|
||||
alias=["rm", "移除", "卸载"],
|
||||
),
|
||||
@ -136,12 +130,12 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
event=event
|
||||
)
|
||||
|
||||
elif result.subcommands.get("remove"):
|
||||
plugin_module_name: str = result.subcommands["remove"].args.get("plugin_name")
|
||||
elif result.subcommands.get("uninstall"):
|
||||
plugin_module_name: str = result.subcommands["uninstall"].args.get("plugin_name")
|
||||
found_installed_plugin: InstalledPlugin = plugin_db.first(InstalledPlugin, "module_name = ?", plugin_module_name)
|
||||
if found_installed_plugin:
|
||||
plugin_db.delete(InstalledPlugin, "module_name = ?", plugin_module_name)
|
||||
reply = f"{ulang.get('npm.remove_success', NAME=found_installed_plugin.module_name)}"
|
||||
reply = f"{ulang.get('npm.uninstall_success', NAME=found_installed_plugin.module_name)}"
|
||||
await npm_alc.finish(reply)
|
||||
else:
|
||||
await npm_alc.finish(ulang.get("npm.plugin_not_installed", NAME=plugin_module_name))
|
||||
|
@ -2,6 +2,7 @@ import os
|
||||
|
||||
import nonebot.plugin
|
||||
from nonebot import on_command
|
||||
from nonebot.exception import FinishedException
|
||||
from nonebot.internal.matcher import Matcher
|
||||
from nonebot.message import run_preprocessor
|
||||
from nonebot.permission import SUPERUSER
|
||||
@ -10,7 +11,7 @@ from nonebot_plugin_alconna import on_alconna, Alconna, Args, Arparma
|
||||
from src.utils.data_manager import GroupChat, InstalledPlugin, User, group_db, plugin_db, user_db
|
||||
from src.utils.message import Markdown as md, send_markdown
|
||||
from src.utils.permission import GROUP_ADMIN, GROUP_OWNER
|
||||
from src.utils.typing import T_Bot, T_MessageEvent
|
||||
from src.utils.ly_typing import T_Bot, T_MessageEvent
|
||||
from src.utils.language import get_user_lang
|
||||
from .common import get_plugin_can_be_toggle, get_plugin_current_enable, get_plugin_default_enable
|
||||
from .installer import get_store_plugin, npm_update
|
||||
@ -62,12 +63,12 @@ async def _(event: T_MessageEvent, bot: T_Bot):
|
||||
if await SUPERUSER(bot, event):
|
||||
plugin_in_database = plugin_db.first(InstalledPlugin, 'module_name = ?', plugin.module_name)
|
||||
# 添加移除插件
|
||||
btn_remove = (
|
||||
md.button(lang.get('npm.uninstall'), f'npm remove {plugin.module_name}')) if plugin_in_database else lang.get(
|
||||
btn_uninstall = (
|
||||
md.button(lang.get('npm.uninstall'), f'npm uninstall {plugin.module_name}')) if plugin_in_database else lang.get(
|
||||
'npm.uninstall')
|
||||
btn_toggle_global = lang.get('npm.disable') if plugin.metadata and not plugin.metadata.extra.get('toggleable') \
|
||||
else md.button(lang.get('npm.disable_global'), f'disable-plugin {plugin.module_name} true')
|
||||
reply += f" {btn_remove} {btn_toggle_global}"
|
||||
reply += f" {btn_uninstall} {btn_toggle_global}"
|
||||
|
||||
reply += "\n\n***\n"
|
||||
await send_markdown(reply, bot, event=event)
|
||||
@ -100,7 +101,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
if await GROUP_ADMIN(bot, event) or await GROUP_OWNER(bot, event) or await SUPERUSER(bot, event):
|
||||
session = group_db.first(GroupChat, "group_id = ?", event.group_id, default=GroupChat(group_id=event.group_id))
|
||||
else:
|
||||
return
|
||||
raise FinishedException(ulang.get("Permission Denied"))
|
||||
# 启用 已停用的默认启用插件 将其从停用列表移除
|
||||
# 启用 已停用的默认停用插件 将其放到启用列表
|
||||
# 停用 已启用的默认启用插件 将其放到停用列表
|
||||
@ -134,4 +135,5 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
@run_preprocessor
|
||||
async def _(event: T_MessageEvent, matcher: Matcher):
|
||||
plugin = matcher.plugin
|
||||
# TODO 插件启用/停用检查hook
|
||||
nonebot.logger.info(f"Plugin: {plugin.module_name}")
|
||||
|
@ -1,14 +1,11 @@
|
||||
from typing import Optional
|
||||
|
||||
from arclet.alconna import Arparma
|
||||
from nonebot import on_command
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot_plugin_alconna import on_alconna, Alconna, Args, Arparma, Option, Subcommand
|
||||
from nonebot_plugin_alconna import Alconna, Args, Arparma, Subcommand, on_alconna
|
||||
|
||||
from src.utils.data import LiteModel
|
||||
from src.utils.typing import T_Bot, T_Message, T_MessageEvent
|
||||
from src.utils.data_manager import User, user_db
|
||||
from src.utils.language import Language, get_all_lang, get_user_lang
|
||||
from src.utils.ly_typing import T_Bot, T_MessageEvent
|
||||
from src.utils.message import Markdown as md, send_markdown
|
||||
|
||||
profile_alc = on_alconna(
|
||||
@ -134,5 +131,5 @@ def set_profile(key: str, value: str) -> bool:
|
||||
return True
|
||||
return False
|
||||
elif key == 'timezone':
|
||||
# TODO
|
||||
# TODO 其他个人信息项目的实现
|
||||
pass
|
||||
|
Reference in New Issue
Block a user