From 33f80c8d1699896b8576bca0f64a59bd98979033 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Tue, 17 Jan 2023 12:30:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20!plugin=E6=8C=87=E4=BB=A4=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=BA=90=E7=A0=81=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/command.py | 13 ++++++-- pkg/utils/updater.py | 75 +++++++++++++++++++------------------------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/pkg/qqbot/command.py b/pkg/qqbot/command.py index b4e1bcc5..aedd6622 100644 --- a/pkg/qqbot/command.py +++ b/pkg/qqbot/command.py @@ -2,6 +2,7 @@ import logging import json import datetime +import os import threading import pkg.openai.session @@ -84,17 +85,23 @@ def plugin_operation(cmd, params, is_admin): reply = [] import pkg.plugin.host as plugin_host + import pkg.utils.updater as updater plugin_list = plugin_host.__plugins__ if len(params) == 0: - reply_str = "[bot]所有插件{}:\n\n".format(len(plugin_list)) + reply_str = "[bot]所有插件({}):\n\n".format(len(plugin_list)) idx = 0 for key in plugin_list: plugin = plugin_list[key] - print(plugin) - reply_str += "#{} {}:\n{}\nv{}\n作者:{}\n\n".format((idx+1), plugin['name'], plugin['description'], + reply_str += "#{} {}:\n{}\nv{}\n作者: {}\n".format((idx+1), plugin['name'], plugin['description'], plugin['version'], plugin['author']) + + if updater.is_repo("/".join(plugin['path'].split('/')[:-1])): + reply_str += "源码: "+updater.get_remote_url("/".join(plugin['path'].split('/')[:-1]))+"\n" + + reply_str += "\n" + idx += 1 reply = [reply_str] diff --git a/pkg/utils/updater.py b/pkg/utils/updater.py index 66a33b73..dbc2c485 100644 --- a/pkg/utils/updater.py +++ b/pkg/utils/updater.py @@ -3,8 +3,7 @@ import datetime import pkg.utils.context -def update_all() -> bool: - """使用dulwich更新源码""" +def check_dulwich_closure(): try: import pkg.utils.pkgmgr pkg.utils.pkgmgr.ensure_dulwich() @@ -15,6 +14,12 @@ def update_all() -> bool: import dulwich except ModuleNotFoundError: raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") + + +def update_all() -> bool: + """使用dulwich更新源码""" + check_dulwich_closure() + import dulwich try: before_commit_id = get_current_commit_id() from dulwich import porcelain @@ -41,18 +46,31 @@ def update_all() -> bool: raise Exception("分支不一致,自动更新仅支持master分支,请手动更新(https://github.com/RockChinQ/QChatGPT/issues/76)") +def is_repo(path: str) -> bool: + """检查是否是git仓库""" + check_dulwich_closure() + + from dulwich import porcelain + try: + porcelain.open_repo(path) + return True + except: + return False + + + +def get_remote_url(repo_path: str) -> str: + """获取远程仓库地址""" + check_dulwich_closure() + + from dulwich import porcelain + repo = porcelain.open_repo(repo_path) + return str(porcelain.get_remote_repo(repo, "origin")[1]) + + def get_current_version_info() -> str: """获取当前版本信息""" - try: - import pkg.utils.pkgmgr - pkg.utils.pkgmgr.ensure_dulwich() - except: - pass - - try: - import dulwich - except ModuleNotFoundError: - raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") + check_dulwich_closure() from dulwich import porcelain @@ -74,16 +92,7 @@ def get_current_version_info() -> str: def get_commit_id_and_time_and_msg() -> str: """获取当前提交id和时间和提交信息""" - try: - import pkg.utils.pkgmgr - pkg.utils.pkgmgr.ensure_dulwich() - except: - pass - - try: - import dulwich - except ModuleNotFoundError: - raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") + check_dulwich_closure() from dulwich import porcelain @@ -97,16 +106,7 @@ def get_commit_id_and_time_and_msg() -> str: def get_current_commit_id() -> str: """检查是否有新版本""" - try: - import pkg.utils.pkgmgr - pkg.utils.pkgmgr.ensure_dulwich() - except: - pass - - try: - import dulwich - except ModuleNotFoundError: - raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") + check_dulwich_closure() from dulwich import porcelain @@ -121,16 +121,7 @@ def get_current_commit_id() -> str: def is_new_version_available() -> bool: """检查是否有新版本""" - try: - import pkg.utils.pkgmgr - pkg.utils.pkgmgr.ensure_dulwich() - except: - pass - - try: - import dulwich - except ModuleNotFoundError: - raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") + check_dulwich_closure() from dulwich import porcelain