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