已经可以顺利运行
This commit is contained in:
@@ -40,36 +40,42 @@ async def callback_receive(request: Request):
|
||||
# 解析指令
|
||||
content = callback_data.content
|
||||
command = content.split(" ")[0]
|
||||
message = content[len(command):].strip()
|
||||
config.Log("Info", f"识别指令: command={command}")
|
||||
|
||||
# TODO: 处理指令
|
||||
return await handle_command(command, content, callback_data.chatid, callback_data.creator)
|
||||
# 处理指令
|
||||
result = await handle_command(command, message, callback_data.chatid, callback_data.creator)
|
||||
if result:
|
||||
return JSONResponse({"result": "ok", "message": result})
|
||||
else:
|
||||
return JSONResponse({"result": "ok"})
|
||||
|
||||
except Exception as e:
|
||||
config.Log("Error", f"处理Callback异常: {e}", exc_info=True)
|
||||
config.Log("Error", f"处理Callback异常: {e}")
|
||||
if ALWAYS_RETURN_OK:
|
||||
return JSONResponse({"result": "ok"})
|
||||
else:
|
||||
return JSONResponse({"result": "error", "message": str(e)})
|
||||
|
||||
|
||||
async def handle_command(command: str, content: str,
|
||||
chat_id: int, user_id: int) -> str:
|
||||
"""处理游戏指令
|
||||
async def handle_command(command: str, message: str,
|
||||
chat_id: int, user_id: int) -> str|None:
|
||||
"""处理指令
|
||||
|
||||
Args:
|
||||
command: 指令
|
||||
content: 消息内容
|
||||
message: 消息内容
|
||||
chat_id: 会话ID
|
||||
user_id: 用户ID
|
||||
|
||||
Returns:
|
||||
回复文本
|
||||
回复文本或None
|
||||
"""
|
||||
try:
|
||||
plugin = PluginInterface.plugin_instances.get(command, None)
|
||||
if plugin:
|
||||
return plugin.callback(content, chat_id, user_id)
|
||||
config.Log("Info", f"已找到插件注册指令: {command}, class: {plugin.__class__.__name__}")
|
||||
return await plugin.callback(message, chat_id, user_id)
|
||||
else:
|
||||
return f"❌ 未识别指令: {command}"
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user