处理角色命令 Args: command_text: 用户命令 feishu_user_id: 飞书用户 ID send_to_feishu: 是否发送飞书 Returns: 处理结果
(
command_text: str,
feishu_user_id: Optional[str] = None,
send_to_feishu: bool = True
)
| 373 | |
| 374 | |
| 375 | def process_role_command( |
| 376 | command_text: str, |
| 377 | feishu_user_id: Optional[str] = None, |
| 378 | send_to_feishu: bool = True |
| 379 | ) -> Dict[str, Any]: |
| 380 | """ |
| 381 | 处理角色命令 |
| 382 | |
| 383 | Args: |
| 384 | command_text: 用户命令 |
| 385 | feishu_user_id: 飞书用户 ID |
| 386 | send_to_feishu: 是否发送飞书 |
| 387 | |
| 388 | Returns: |
| 389 | 处理结果 |
| 390 | """ |
| 391 | import re |
| 392 | |
| 393 | command = parse_role_command(command_text) |
| 394 | |
| 395 | if not command: |
| 396 | return {"success": False, "message": "未识别到有效命令"} |
| 397 | |
| 398 | action = command.get("action") |
| 399 | |
| 400 | if action == "create": |
| 401 | result = create_role( |
| 402 | role_name=command["role_name"], |
| 403 | natural_language=command.get("natural_language", ""), |
| 404 | feishu_chat_id=command.get("feishu_chat_id"), |
| 405 | ) |
| 406 | elif action == "bind": |
| 407 | result = bind_chat_id( |
| 408 | role_name=command["role_name"], |
| 409 | feishu_chat_id=command["feishu_chat_id"], |
| 410 | ) |
| 411 | elif action == "switch": |
| 412 | result = switch_role(command["role_name"]) |
| 413 | elif action == "list": |
| 414 | result = list_roles() |
| 415 | if result["success"]: |
| 416 | result["formatted"] = format_role_list(result) |
| 417 | elif action == "delete": |
| 418 | result = delete_role(command["role_name"]) |
| 419 | else: |
| 420 | result = {"success": False, "message": "未知命令"} |
| 421 | |
| 422 | # 发送到飞书 |
| 423 | if send_to_feishu and feishu_user_id and result.get("success"): |
| 424 | if "formatted" in result: |
| 425 | send_text(feishu_user_id, result["formatted"]) |
| 426 | else: |
| 427 | send_text(feishu_user_id, result.get("message", "操作完成")) |
| 428 | |
| 429 | return result |
| 430 | |
| 431 | |
| 432 | if __name__ == "__main__": |
no test coverage detected