Disable Telegram link previews in market digest messages

This commit is contained in:
2569718930@qq.com
2026-04-01 20:07:03 +08:00
parent 9dc21a3088
commit fdcc57339b
2 changed files with 31 additions and 15 deletions
+2 -2
View File
@@ -266,7 +266,7 @@ class BasicCommandHandler:
cached_summary = load_cached_market_monitor_digest()
if cached_summary:
self.bot.reply_to(message, cached_summary)
self.bot.reply_to(message, cached_summary, disable_web_page_preview=True)
else:
self.bot.reply_to(message, "⏳ 正在生成当前市场概览,请稍候...")
@@ -278,7 +278,7 @@ class BasicCommandHandler:
force_refresh=False,
)
if not cached_summary or summary.strip() != cached_summary.strip():
self.bot.send_message(chat_id, summary)
self.bot.send_message(chat_id, summary, disable_web_page_preview=True)
except Exception:
if not cached_summary:
self.bot.send_message(chat_id, "❌ 当前市场概览生成失败,请稍后重试。")
+29 -13
View File
@@ -444,6 +444,24 @@ def _focus_trigger_summary(alert_payload: Dict[str, Any]) -> str:
return _join_trigger_types_cn_local(rules) or "市场与天气分歧待观察"
def _shortlist_focus_payloads(
payloads: List[Dict[str, Any]],
*,
top_n: int,
) -> List[Dict[str, Any]]:
ranked = sorted(
payloads,
key=lambda item: _market_monitor_score(item),
reverse=True,
)
return [
item for item in ranked
if _market_monitor_score(item) > 0
and bool((item.get("market_snapshot") or {}).get("available"))
and _market_price_cap_ok(item, require_actionable_quote=True)
][:top_n]
def _build_focus_digest_message(
payloads: List[Dict[str, Any]],
*,
@@ -454,17 +472,7 @@ def _build_focus_digest_message(
digest_interval = _format_interval_brief(
_env_int("TELEGRAM_MARKET_FOCUS_DIGEST_INTERVAL_SEC", 1800),
)
ranked = sorted(
payloads,
key=lambda item: _market_monitor_score(item),
reverse=True,
)
shortlisted = [
item for item in ranked
if _market_monitor_score(item) > 0
and bool((item.get("market_snapshot") or {}).get("available"))
and _market_price_cap_ok(item, require_actionable_quote=True)
][:top_n]
shortlisted = _shortlist_focus_payloads(payloads, top_n=top_n)
if not shortlisted:
return ""
@@ -546,6 +554,14 @@ def _maybe_send_focus_digest(
if last_digest_ts and now_ts - last_digest_ts < digest_interval_sec:
return False
shortlisted = _shortlist_focus_payloads(payloads, top_n=top_n)
if not shortlisted:
return False
high_priority_count = sum(1 for item in shortlisted if _market_monitor_score(item) >= 72)
# Tighten channel pushes: require either multiple candidates or one truly high-priority market.
if len(shortlisted) < 2 and high_priority_count < 1:
return False
local_now = datetime.now().astimezone()
hour = local_now.hour
if 6 <= hour < 15:
@@ -555,7 +571,7 @@ def _maybe_send_focus_digest(
else:
slot_label = "夜间关注"
message = _build_focus_digest_message(
payloads,
shortlisted,
slot_label=slot_label,
top_n=top_n,
)
@@ -571,7 +587,7 @@ def _maybe_send_focus_digest(
sent_count = 0
for chat_id in chat_ids:
try:
bot.send_message(chat_id, message)
bot.send_message(chat_id, message, disable_web_page_preview=True)
sent_count += 1
except Exception as exc:
logger.warning(