From 6acd7be5471c8f6f1ed1a25c4b4b9c06dc52cbdd Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 1 Oct 2023 17:46:51 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=BA=93=E7=9A=84=E5=AF=BC=E5=85=A5=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 6 +++--- model/command/command.py | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index e9fe70fdc..73ad2474a 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -25,9 +25,6 @@ from nakuru import ( from nakuru.entities.components import Plain,At,Image from model.provider.provider import Provider from model.command.command import Command -from model.command.command_rev_chatgpt import CommandRevChatGPT -from model.command.command_rev_edgegpt import CommandRevEdgeGPT -from model.command.command_openai_official import CommandOpenAIOfficial from util import general_utils as gu from util.cmd_config import CmdConfig as cc import util.gplugin as gplugin @@ -235,6 +232,7 @@ def initBot(cfg, prov): if cfg['rev_ChatGPT']['enable']: if 'account' in cfg['rev_ChatGPT']: from model.provider.provider_rev_chatgpt import ProviderRevChatGPT + from model.command.command_rev_chatgpt import CommandRevChatGPT llm_instance[REV_CHATGPT] = ProviderRevChatGPT(cfg['rev_ChatGPT'], base_url=cc.get("CHATGPT_BASE_URL", None)) llm_command_instance[REV_CHATGPT] = CommandRevChatGPT(llm_instance[REV_CHATGPT], _global_object) chosen_provider = REV_CHATGPT @@ -249,6 +247,7 @@ def initBot(cfg, prov): if cfg['rev_edgegpt']['enable']: try: from model.provider.provider_rev_edgegpt import ProviderRevEdgeGPT + from model.command.command_rev_edgegpt import CommandRevEdgeGPT llm_instance[REV_EDGEGPT] = ProviderRevEdgeGPT() llm_command_instance[REV_EDGEGPT] = CommandRevEdgeGPT(llm_instance[REV_EDGEGPT], _global_object) chosen_provider = REV_EDGEGPT @@ -258,6 +257,7 @@ def initBot(cfg, prov): gu.log("- OpenAI官方 -", gu.LEVEL_INFO) if cfg['openai']['key'] is not None: from model.provider.provider_openai_official import ProviderOpenAIOfficial + from model.command.command_openai_official import CommandOpenAIOfficial llm_instance[OPENAI_OFFICIAL] = ProviderOpenAIOfficial(cfg['openai']) llm_command_instance[OPENAI_OFFICIAL] = CommandOpenAIOfficial(llm_instance[OPENAI_OFFICIAL], _global_object) chosen_provider = OPENAI_OFFICIAL diff --git a/model/command/command.py b/model/command/command.py index 7a06f8d8f..67441b751 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -1,6 +1,13 @@ import json -import git.exc -from git.repo import Repo + +has_git = True +try: + import git.exc + from git.repo import Repo +except BaseException as e: + print("你正在运行在无Git环境下,暂时将无法使用插件、热更新功能。") + has_git = False + import os import sys import requests @@ -142,6 +149,8 @@ class Command: 插件指令 ''' def plugin_oper(self, message: str, role: str, cached_plugins: dict, platform: str): + if not has_git: + return False, "你正在运行在无Git环境下,暂时将无法使用插件、热更新功能。", "plugin" l = message.split(" ") if len(l) < 2: p = gu.create_text_image("【插件指令面板】", "安装插件: \nplugin i 插件Github地址\n卸载插件: \nplugin d 插件名 \n重载插件: \nplugin reload\n查看插件列表:\nplugin l\n更新插件: plugin u 插件名\n") @@ -418,6 +427,8 @@ class Command: return False, "设置失败: "+str(e), "keyword" def update(self, message: str, role: str): + if not has_git: + return False, "你正在运行在无Git环境下,暂时将无法使用插件、热更新功能。", "update" if role != "admin": return True, "你没有权限使用该指令", "keyword" l = message.split(" ")