处理必读清单命令 Args: user_id: 用户 ID command_text: 用户命令文本 feishu_user_id: 飞书用户 ID(open_id,用于发送消息) chat_id: 聊天 ID(优先使用,发送到原对话框) send_to_feishu: 是否发送飞书 Returns: 处理结果
(
user_id: str,
command_text: str,
feishu_user_id: Optional[str] = None,
chat_id: Optional[str] = None,
send_to_feishu: bool = True
)
| 494 | |
| 495 | |
| 496 | def process_must_read_command( |
| 497 | user_id: str, |
| 498 | command_text: str, |
| 499 | feishu_user_id: Optional[str] = None, |
| 500 | chat_id: Optional[str] = None, |
| 501 | send_to_feishu: bool = True |
| 502 | ) -> Dict[str, Any]: |
| 503 | """ |
| 504 | 处理必读清单命令 |
| 505 | |
| 506 | Args: |
| 507 | user_id: 用户 ID |
| 508 | command_text: 用户命令文本 |
| 509 | feishu_user_id: 飞书用户 ID(open_id,用于发送消息) |
| 510 | chat_id: 聊天 ID(优先使用,发送到原对话框) |
| 511 | send_to_feishu: 是否发送飞书 |
| 512 | |
| 513 | Returns: |
| 514 | 处理结果 |
| 515 | """ |
| 516 | print(f"Processing must-read command: {command_text!r}") |
| 517 | |
| 518 | # 解析命令 |
| 519 | command = parse_command(command_text) |
| 520 | |
| 521 | # 优先使用 chat_id,否则使用 feishu_user_id |
| 522 | target_id = chat_id or feishu_user_id |
| 523 | use_chat_id = chat_id is not None |
| 524 | |
| 525 | if not command: |
| 526 | message = "未识别到有效命令。支持:\n • 添加必读作者/机构/关键词\n • 移除必读作者/机构/关键词\n • 查看必读清单" |
| 527 | if send_to_feishu and target_id: |
| 528 | send_text(target_id, message, use_chat_id=use_chat_id) |
| 529 | return {"success": False, "message": message} |
| 530 | |
| 531 | # 获取用户画像 |
| 532 | profile = get_profile(user_id) |
| 533 | if not profile: |
| 534 | message = "未找到用户画像" |
| 535 | if send_to_feishu and target_id: |
| 536 | send_text(target_id, message, use_chat_id=use_chat_id) |
| 537 | return {"success": False, "message": message} |
| 538 | |
| 539 | # 执行操作 |
| 540 | if command["action"] == "list": |
| 541 | result_text = format_must_read_list(profile) |
| 542 | if send_to_feishu and target_id: |
| 543 | send_text(target_id, result_text, use_chat_id=use_chat_id) |
| 544 | return {"success": True, "action": "list"} |
| 545 | |
| 546 | elif command["action"] == "add": |
| 547 | result = add_must_read(profile, command["type"], command["value"]) |
| 548 | if result["success"]: |
| 549 | # 保存更新 |
| 550 | update_profile(user_id, profile) |
| 551 | |
| 552 | # 记录行为日志 |
| 553 | log_behavior( |
no test coverage detected