From c50bcdbdb9a8b6517f861b35a82164c16f1ff474 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 2 Aug 2024 22:48:04 +0800 Subject: [PATCH] fix: Register command only if plugin is found --- model/command/manager.py | 3 ++- model/plugin/manager.py | 4 +++- model/provider/openai_official.py | 4 +++- util/updator/astrbot_updator.py | 6 +++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/model/command/manager.py b/model/command/manager.py index f79677089..697ce2171 100644 --- a/model/command/manager.py +++ b/model/command/manager.py @@ -64,7 +64,8 @@ class CommandManager(): break if not plugin: logger.warning(f"插件 {request.plugin_name} 未找到,无法注册指令 {request.command_name}。") - self.register(request.command_name, request.description, request.priority, request.handler, plugin.metadata) + else: + self.register(request.command_name, request.description, request.priority, request.handler, plugin.metadata) self.plugin_commands_waitlist = [] async def scan_command(self, message_event: AstrMessageEvent, context: Context) -> CommandResult: diff --git a/model/plugin/manager.py b/model/plugin/manager.py index 62f96577e..d89296505 100644 --- a/model/plugin/manager.py +++ b/model/plugin/manager.py @@ -166,8 +166,10 @@ class PluginManager(): try: # 尝试传入 ctx obj = getattr(module, cls[0])(context=self.context) - except: + except TypeError: obj = getattr(module, cls[0])() + except BaseException as e: + raise e metadata = None diff --git a/model/provider/openai_official.py b/model/provider/openai_official.py index ac156cdb1..b5eefcd23 100644 --- a/model/provider/openai_official.py +++ b/model/provider/openai_official.py @@ -385,7 +385,9 @@ class ProviderOpenAIOfficial(Provider): assert isinstance(completion, ChatCompletion) logger.debug(f"openai completion: {completion.usage}") - + + if len(completion.choices) == 0: + raise Exception("OpenAI API 返回的 completion 为空。") choice = completion.choices[0] usage_tokens = completion.usage.total_tokens diff --git a/util/updator/astrbot_updator.py b/util/updator/astrbot_updator.py index a055f0c04..eccdf2089 100644 --- a/util/updator/astrbot_updator.py +++ b/util/updator/astrbot_updator.py @@ -35,7 +35,11 @@ class AstrBotUpdator(RepoZipUpdator): py = sys.executable self.terminate_child_processes() py = py.replace(" ", "\\ ") - os.execl(py, py, *sys.argv) + try: + os.execl(py, py, *sys.argv) + except Exception as e: + logger.error(f"重启失败({py}, {e}),请尝试手动重启。") + raise e def check_update(self, url: str, current_version: str) -> ReleaseInfo: return super().check_update(self.ASTRBOT_RELEASE_API, VERSION)