fix: call middleware

This commit is contained in:
Soulter
2024-09-11 04:59:49 -04:00
parent a93e6ff01a
commit 6fd70ed26a
4 changed files with 7 additions and 11 deletions
-5
View File
@@ -25,11 +25,6 @@ class HelloWorldPlugin:
def __init__(self, context: Context) -> None:
self.context = context
self.context.register_commands("helloworld", "helloworld", "内置测试指令。", 1, self.helloworld)
self.context.register_middleware("audio_to_text", self.audio_to_text)
async def audio_to_text(self, message: AstrMessageEvent, context: Context):
print(message)
"""
指令处理函数。
+2 -1
View File
@@ -158,7 +158,8 @@ class MessageHandler():
# middlewares
for middleware in self.context.middlewares:
try:
await middleware.func(message)
logger.info(f"执行中间件 {middleware.origin}/{middleware.name}...")
await middleware.func(message, self.context)
except BaseException as e:
logger.error(f"中间件 {middleware.origin}/{middleware.name} 处理消息时发生异常:{e},跳过。")
logger.error(traceback.format_exc())
+3 -3
View File
@@ -181,18 +181,18 @@ class InternalCommandHandler:
except BaseException as e:
logger.warning("An error occurred while fetching astrbot notice. Never mind, it's not important.")
msg = "# Help Center\n## 指令列表\n"
msg = "# 帮助中心\n## 指令\n"
for key, value in self.manager.commands_handler.items():
if value.plugin_metadata:
msg += f"- `{key}` ({value.plugin_metadata.plugin_name}): {value.description}\n"
else: msg += f"- `{key}`: {value.description}\n"
# plugins
if context.cached_plugins != None:
if context.cached_plugins:
plugin_list_info = ""
for plugin in context.cached_plugins:
plugin_list_info += f"- `{plugin.metadata.plugin_name}` {plugin.metadata.desc}\n"
if plugin_list_info.strip() != "":
msg += "\n## 插件列表\n> 使用plugin v 插件名 查看插件帮助\n"
msg += "\n## 插件\n> 使用plugin v 插件名 查看插件帮助\n"
msg += plugin_list_info
msg += notice
+2 -2
View File
@@ -4,5 +4,5 @@ from dataclasses import dataclass
class Middleware():
name: str = ""
description: str = ""
func: callable = None
origin: str # 注册来源
origin: str = "" # 注册来源
func: callable = None