[v4.11.1] - 🛠️ 修复 QQ 官方机器人昵称与提及清洗 (#207)

Fix QQ official nickname and mention handling 

* fix: restore QQ official nicknames and sanitize mentions

* fix: protect QQ official identities and whitespace

* docs: update QQ official nickname guidance

* chore: bump version to v4.11.1

* docs: remove obsolete PDF guidance

* chore: finalize v4.11.1 release prep

* fix(qqofficial): 修复 _sanitize_qq_official_mentions .strip() 吞换行,补充 allow_alphanumeric_user_ids 注释

- .strip() → .strip(' \t'):仅清除首尾空白/制表符,保留用户创作的 \n 换行
- allow_alphanumeric_user_ids:在参数定义处补充注释,说明该标记还控制 ID 正则化和回退显示名
- 响应 Sourcery 代码审查 #207 指出的问题

* chore:  删除不必要的描述

---------

Co-authored-by: SXP-Simon <sxp20061207@163.com>
This commit is contained in:
clown145
2026-07-21 14:53:31 +08:00
committed by GitHub
co-authored by SXP-Simon
parent 20019baa2c
commit f2bcd6801e
13 changed files with 442 additions and 41 deletions
+16 -10
View File
@@ -622,7 +622,7 @@ class GroupDailyAnalysis(Star):
analysis_result = result["analysis_result"]
adapter = result["adapter"]
output_format = self.config_manager.get_output_format()
hide_user_names = adapter.get_platform_name() == "qq_official"
is_qq_official = adapter.get_platform_name() == "qq_official"
# 定义获取回调
async def avatar_url_getter(user_id: str) -> str | None:
@@ -645,7 +645,7 @@ class GroupDailyAnalysis(Star):
avatar_url_getter=avatar_url_getter,
nickname_getter=nickname_getter,
avatar_cache_namespace=platform_id,
hide_user_names=hide_user_names,
allow_alphanumeric_user_ids=is_qq_official,
)
if image_url:
@@ -658,7 +658,7 @@ class GroupDailyAnalysis(Star):
# 如果图片生成或发送失败,直接回退到文本
logger.warning(f"图片报告发送失败,正在发送文本回退报告。群: {group_id}")
await self._send_text_reports(
group_id, analysis_result, hide_user_names, adapter
group_id, analysis_result, is_qq_official, adapter
)
return
@@ -669,7 +669,7 @@ class GroupDailyAnalysis(Star):
avatar_url_getter=avatar_url_getter,
nickname_getter=nickname_getter,
avatar_cache_namespace=platform_id,
hide_user_names=hide_user_names,
allow_alphanumeric_user_ids=is_qq_official,
)
if html_path:
is_only_url = self.config_manager.get_html_only_url()
@@ -731,25 +731,31 @@ class GroupDailyAnalysis(Star):
else:
await self._send_text_reports(
group_id, analysis_result, hide_user_names, adapter
group_id, analysis_result, is_qq_official, adapter
)
async def _generate_text_reports(
self, analysis_result: dict, hide_user_names: bool
self, analysis_result: dict, use_qq_official_markdown: bool
) -> tuple[str, str | None]:
"""Generate text or QQ-official-markdown reports."""
if hide_user_names:
if use_qq_official_markdown:
return await self.report_generator.generate_qq_official_markdown_report(
analysis_result, self.html_render
)
return self.report_generator.generate_text_report(analysis_result), None
async def _send_text_reports(
self, group_id: str, analysis_result: dict, hide_user_names: bool, adapter
self,
group_id: str,
analysis_result: dict,
use_qq_official_markdown: bool,
adapter,
) -> bool:
"""Send text reports via platform adapter."""
tr, fr = await self._generate_text_reports(analysis_result, hide_user_names)
if hide_user_names:
tr, fr = await self._generate_text_reports(
analysis_result, use_qq_official_markdown
)
if use_qq_official_markdown:
return await adapter.send_text_report(group_id, tr, fallback_content=fr)
return await adapter.send_text_report(group_id, tr)