fix: 修复TG分页取数与话题白名单匹配

This commit is contained in:
clown145
2026-02-12 15:41:07 +08:00
committed by Helian Nuits
parent 7a79cb7b3e
commit cb0f4e0faf
3 changed files with 42 additions and 10 deletions
+25 -3
View File
@@ -68,15 +68,37 @@ class ConfigManager:
else target_simple_id
)
def _is_match(item: str, target: str, target_simple_id: str) -> bool:
def _is_match(
item: str,
target: str,
target_simple_id: str,
target_parent_id: str,
) -> bool:
if ":" in item:
return item == target
if item == target:
return True
# 允许 Telegram 话题会话通过“父 UMO”命中,
# 例如: item=telegram2:GroupMessage:-1001
# target=telegram2:GroupMessage:-1001#2264
if "#" in target_simple_id:
if ":" not in target:
return False
item_prefix, item_tail = item.rsplit(":", 1)
target_prefix, _ = target.rsplit(":", 1)
return (
item_prefix == target_prefix and item_tail == target_parent_id
)
return False
if item == target_simple_id:
return True
# 允许 Telegram 话题会话通过父群 ID 命中简单群号白/黑名单
return "#" in target_simple_id and item == target_parent_id
is_in_list = any(_is_match(item, target, target_simple_id) for item in glist)
is_in_list = any(
_is_match(item, target, target_simple_id, target_parent_id)
for item in glist
)
if mode == "whitelist":
return is_in_list
@@ -218,8 +218,10 @@ class TelegramAdapter(PlatformAdapter):
group_id, msg, sender_name_cache
)
messages.append(msg)
if len(messages) >= target_count:
break
# 当前页完整处理后已足够,停止继续翻更旧页面。
if len(messages) >= target_count:
break
# 下一页一定更旧,若当前页最旧记录已越过时间窗口则可提前停止
if oldest_record_time and oldest_record_time < cutoff_time:
@@ -813,7 +815,7 @@ class TelegramAdapter(PlatformAdapter):
return uid, None
pairs = await asyncio.gather(*(_fetch_avatar(uid) for uid in user_ids))
return {uid: avatar_url for uid, avatar_url in pairs}
return dict(pairs)
# ==================== 辅助方法 ====================