From 3a1d5d890450030961ccf95f278d1861c4599566 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 14 Dec 2023 17:11:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20/update=20checkout=20?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E6=94=AF=E6=8C=81=E5=88=87=E6=8D=A2=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/command/command.py | 56 +++++++++++++++++++++------------------- nonebot_plugin_gspanel | 1 + 2 files changed, 31 insertions(+), 26 deletions(-) create mode 160000 nonebot_plugin_gspanel diff --git a/model/command/command.py b/model/command/command.py index 15ef84383..907bf58f3 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -448,18 +448,21 @@ class Command: if role != "admin": return True, "你没有权限使用该指令", "keyword" l = message.split(" ") - if len(l) == 1: - # 得到本地版本号和最新版本号 + try: + repo = Repo() + except git.exc.InvalidGitRepositoryError: try: - repo = Repo() + repo = Repo(path="QQChannelChatGPT") except git.exc.InvalidGitRepositoryError: - repo = Repo(path="QQChannelChatGPT") + repo = Repo(path="AstrBot") + if len(l) == 1: + curr_branch = repo.active_branch.name + # 得到本地版本号和最新版本号 now_commit = repo.head.commit - # 得到远程3条commit列表, 包含commit信息 origin = repo.remotes.origin origin.fetch() - commits = list(repo.iter_commits('master', max_count=3)) + commits = list(repo.iter_commits(curr_branch, max_count=3)) commits_log = '' index = 1 for commit in commits: @@ -469,38 +472,39 @@ class Command: commits_log += f"[{index}] {commit.message}\n-----------\n" index+=1 remote_commit_hash = origin.refs.master.commit.hexsha[:6] - - return True, f"当前版本: {now_commit.hexsha[:6]}\n最新版本: {remote_commit_hash}\n\n3条commit(非最新):\n{str(commits_log)}\n使用update latest更新至最新版本\n", "update" + return True, f"当前分支: {curr_branch}\n当前版本: {now_commit.hexsha[:6]}\n最新版本: {remote_commit_hash}\n\n3条commit(非最新):\n{str(commits_log)}\nTips:\n1. 使用 update latest 更新至最新版本;\n2. 使用 update checkout <分支名> 切换代码分支。", "update" else: if l[1] == "latest": - pash_tag = "" try: - try: - repo = Repo() - except git.exc.InvalidGitRepositoryError: - repo = Repo(path="QQChannelChatGPT") - pash_tag = "QQChannelChatGPT"+os.sep - repo.remotes.origin.pull() - - try: - origin = repo.remotes.origin - origin.fetch() - commits = list(repo.iter_commits('master', max_count=1)) - commit_log = commits[0].message - except BaseException as e: - commit_log = "无法获取commit信息" - + origin = repo.remotes.origin + origin.fetch() + commits = list(repo.iter_commits('master', max_count=1)) + commit_log = commits[0].message tag = "update" if len(l) == 3 and l[2] == "r": tag = "update latest r" - return True, f"更新成功。新版本内容: \n{commit_log}\nps:重启后生效。输入update r重启(重启指令不返回任何确认信息)。", tag - except BaseException as e: return False, "更新失败: "+str(e), "update" if l[1] == "r": py = sys.executable os.execl(py, py, *sys.argv) + if l[1] == 'checkout': + # 切换分支 + if len(l) < 3: + return False, "请提供分支名,如 /update checkout dev_dashboard", "update" + try: + origin = repo.remotes.origin + origin.fetch() + repo.git.checkout(l[2]) + + # 获得最新的 commit + commits = list(repo.iter_commits(max_count=1)) + commit_log = commits[0].message + + return True, f"切换分支成功,机器人将在 5 秒内重新启动以应用新的功能。\n当前分支: {l[2]}\n此分支最近更新: \n{commit_log}", "update latest r" + except BaseException as e: + return False, f"切换分支失败。原因: {str(e)}", "update" def reset(self): return False diff --git a/nonebot_plugin_gspanel b/nonebot_plugin_gspanel new file mode 160000 index 000000000..a6e45d311 --- /dev/null +++ b/nonebot_plugin_gspanel @@ -0,0 +1 @@ +Subproject commit a6e45d3114f7f90d2d34c0b46fc87253da5514be From 8b9ca08903a85b6a71490f88981aa481e8396ce1 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:18:08 +0800 Subject: [PATCH 2/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4f846c4cd..e9073655c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ ## 🧩功能: +✨ 最近功能: +1. 支持切换代码分支。输入`/update checkout <分支名>`即可切换代码分支 +2. 正在测试可视化面板,输入`/update checkout dev_dashboard`后根据提示即可体验 + 🌍支持的AI语言模型一览: **文字模型/图片理解** From 07ecdedf0d1a01e216134cc2ecdaa10a4a534eff Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Thu, 14 Dec 2023 20:05:58 +0800 Subject: [PATCH 3/4] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e9073655c..5e60d11b8 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,9 @@ - `liferestart`: https://github.com/Soulter/liferestart | 人生重开模拟器 +image + +