From e0dc8401979b865eb965b86e45dfcdf7157ac51b Mon Sep 17 00:00:00 2001 From: snowy Date: Wed, 10 Apr 2024 12:16:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=90=E4=BE=9B=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_pacman/common.py | 2 +- liteyuki/plugins/liteyuki_pacman/npm.py | 20 ++++++++++++++------ liteyuki/resources/lang/zh-CN.lang | 4 +++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/liteyuki/plugins/liteyuki_pacman/common.py b/liteyuki/plugins/liteyuki_pacman/common.py index 60d7d16d..8d4b28e1 100644 --- a/liteyuki/plugins/liteyuki_pacman/common.py +++ b/liteyuki/plugins/liteyuki_pacman/common.py @@ -30,7 +30,7 @@ class StorePlugin(LiteModel): def get_plugin_exist(plugin_name: str) -> bool: """ - 获取插件是否存在 + 获取插件是否存在于加载列表 Args: plugin_name: diff --git a/liteyuki/plugins/liteyuki_pacman/npm.py b/liteyuki/plugins/liteyuki_pacman/npm.py index 5f8f7c2d..0586f215 100644 --- a/liteyuki/plugins/liteyuki_pacman/npm.py +++ b/liteyuki/plugins/liteyuki_pacman/npm.py @@ -213,7 +213,10 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot, npm: Matcher): if len(rs): reply = f"{ulang.get('npm.search_result')} | {ulang.get('npm.total', TOTAL=len(rs))}\n***" for storePlugin in rs[:min(max_show, len(rs))]: - btn_install = md.btn_cmd(ulang.get("npm.install"), "npm install %s" % storePlugin.module_name) + btn_install_or_update = md.btn_cmd( + ulang.get("npm.update") if get_plugin_exist(storePlugin.module_name) else ulang.get("npm.install"), + "npm install %s" % storePlugin.module_name + ) link_page = md.btn_link(ulang.get("npm.homepage"), storePlugin.homepage) link_pypi = md.btn_link(ulang.get("npm.pypi"), storePlugin.homepage) @@ -221,7 +224,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot, npm: Matcher): f"\n> **{storePlugin.desc}**\n" f"\n> {ulang.get('npm.author')}: {storePlugin.author}" f"\n> *{md.escape(storePlugin.module_name)}*" - f"\n> {btn_install} {link_page} {link_pypi}\n\n***\n") + f"\n> {btn_install_or_update} {link_page} {link_pypi}\n\n***\n") if len(rs) > max_show: reply += f"\n{ulang.get('npm.too_many_results', HIDE_NUM=len(rs) - max_show)}" else: @@ -431,10 +434,12 @@ def npm_install(plugin_package_name) -> tuple[bool, str]: sys.stdout = buffer sys.stderr = buffer + update = False + if get_plugin_exist(plugin_package_name): + update = True + mirrors = [ "https://pypi.tuna.tsinghua.edu.cn/simple", # 清华大学 - "https://pypi.mirrors.cqupt.edu.cn/simple", # 重庆邮电大学 - "https://pypi.liteyuki.icu/simple", # 轻雪代理镜像 "https://pypi.org/simple", # 官方源 ] @@ -442,8 +447,11 @@ def npm_install(plugin_package_name) -> tuple[bool, str]: success = False for mirror in mirrors: try: - nonebot.logger.info(f"npm_install try mirror: {mirror}") - result = pip.main(["install", plugin_package_name, "-i", mirror]) + nonebot.logger.info(f"pip install try mirror: {mirror}") + if update: + result = pip.main(["install", "--upgrade", plugin_package_name, "-i", mirror]) + else: + result = pip.main(["install", plugin_package_name, "-i", mirror]) success = result == 0 if success: break diff --git a/liteyuki/resources/lang/zh-CN.lang b/liteyuki/resources/lang/zh-CN.lang index 56dcbedd..13e9c4c2 100644 --- a/liteyuki/resources/lang/zh-CN.lang +++ b/liteyuki/resources/lang/zh-CN.lang @@ -119,4 +119,6 @@ liteyuki.change_priority_success=资源包 {NAME} 优先级修改成功 liteyuki.change_priority_failed=资源包 {NAME} 优先级修改失败 rpm.move_up=上移 rpm.move_down=下移 -rpm.move_top=置顶 \ No newline at end of file +rpm.move_top=置顶 + +npm.update=更新 \ No newline at end of file