From 3dec627d40d0d9b58adc46f5d7d508552b8fb144 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 5 Jan 2023 15:34:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0!version=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/process.py | 2 ++ pkg/utils/updater.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 9fcf4449..4b98ddd2 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -242,6 +242,8 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes if not (hasattr(config, 'include_image_description') and not config.include_image_description): reply.append(" ".join(params)) + elif cmd == 'version': + reply = ["[bot]当前版本:\n{}".format(pkg.utils.updater.get_current_version_info())] elif cmd == 'reload' and launcher_type == 'person' and launcher_id == config.admin_qq: def reload_task(): pkg.utils.reloader.reload_all() diff --git a/pkg/utils/updater.py b/pkg/utils/updater.py index 945f615c..81a0b63e 100644 --- a/pkg/utils/updater.py +++ b/pkg/utils/updater.py @@ -1,3 +1,5 @@ +import time + def update_all(): """使用dulwich更新源码""" @@ -13,3 +15,26 @@ def update_all(): raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") except dulwich.porcelain.DivergedBranches: raise Exception("分支不一致,自动更新仅支持master分支,请手动更新(https://github.com/RockChinQ/QChatGPT/issues/76)") + + +def get_current_version_info() -> str: + """获取当前版本信息""" + try: + import dulwich + except ModuleNotFoundError: + raise Exception("dulwich模块未安装,请查看 https://github.com/RockChinQ/QChatGPT/issues/77") + + from dulwich import porcelain + + repo = porcelain.open_repo('.') + + version_str = "" + + for entry in repo.get_walker(): + version_str += "提交编号: "+str(entry.commit.id)[2:9] + "\n" + version_str += "时间: "+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(entry.commit.author_time)) + "\n" + version_str += "说明: "+str(entry.commit.message, encoding="utf-8").strip() + "\n" + version_str += "提交作者: '" + str(entry.commit.author)[2:-1] + "'" + break + + return version_str