Disable Telegram link previews in market digest messages
This commit is contained in:
@@ -266,7 +266,7 @@ class BasicCommandHandler:
|
|||||||
|
|
||||||
cached_summary = load_cached_market_monitor_digest()
|
cached_summary = load_cached_market_monitor_digest()
|
||||||
if cached_summary:
|
if cached_summary:
|
||||||
self.bot.reply_to(message, cached_summary)
|
self.bot.reply_to(message, cached_summary, disable_web_page_preview=True)
|
||||||
else:
|
else:
|
||||||
self.bot.reply_to(message, "⏳ 正在生成当前市场概览,请稍候...")
|
self.bot.reply_to(message, "⏳ 正在生成当前市场概览,请稍候...")
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ class BasicCommandHandler:
|
|||||||
force_refresh=False,
|
force_refresh=False,
|
||||||
)
|
)
|
||||||
if not cached_summary or summary.strip() != cached_summary.strip():
|
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:
|
except Exception:
|
||||||
if not cached_summary:
|
if not cached_summary:
|
||||||
self.bot.send_message(chat_id, "❌ 当前市场概览生成失败,请稍后重试。")
|
self.bot.send_message(chat_id, "❌ 当前市场概览生成失败,请稍后重试。")
|
||||||
|
|||||||
+29
-13
@@ -444,6 +444,24 @@ def _focus_trigger_summary(alert_payload: Dict[str, Any]) -> str:
|
|||||||
return _join_trigger_types_cn_local(rules) or "市场与天气分歧待观察"
|
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(
|
def _build_focus_digest_message(
|
||||||
payloads: List[Dict[str, Any]],
|
payloads: List[Dict[str, Any]],
|
||||||
*,
|
*,
|
||||||
@@ -454,17 +472,7 @@ def _build_focus_digest_message(
|
|||||||
digest_interval = _format_interval_brief(
|
digest_interval = _format_interval_brief(
|
||||||
_env_int("TELEGRAM_MARKET_FOCUS_DIGEST_INTERVAL_SEC", 1800),
|
_env_int("TELEGRAM_MARKET_FOCUS_DIGEST_INTERVAL_SEC", 1800),
|
||||||
)
|
)
|
||||||
ranked = sorted(
|
shortlisted = _shortlist_focus_payloads(payloads, top_n=top_n)
|
||||||
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]
|
|
||||||
if not shortlisted:
|
if not shortlisted:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@@ -546,6 +554,14 @@ def _maybe_send_focus_digest(
|
|||||||
if last_digest_ts and now_ts - last_digest_ts < digest_interval_sec:
|
if last_digest_ts and now_ts - last_digest_ts < digest_interval_sec:
|
||||||
return False
|
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()
|
local_now = datetime.now().astimezone()
|
||||||
hour = local_now.hour
|
hour = local_now.hour
|
||||||
if 6 <= hour < 15:
|
if 6 <= hour < 15:
|
||||||
@@ -555,7 +571,7 @@ def _maybe_send_focus_digest(
|
|||||||
else:
|
else:
|
||||||
slot_label = "夜间关注"
|
slot_label = "夜间关注"
|
||||||
message = _build_focus_digest_message(
|
message = _build_focus_digest_message(
|
||||||
payloads,
|
shortlisted,
|
||||||
slot_label=slot_label,
|
slot_label=slot_label,
|
||||||
top_n=top_n,
|
top_n=top_n,
|
||||||
)
|
)
|
||||||
@@ -571,7 +587,7 @@ def _maybe_send_focus_digest(
|
|||||||
sent_count = 0
|
sent_count = 0
|
||||||
for chat_id in chat_ids:
|
for chat_id in chat_ids:
|
||||||
try:
|
try:
|
||||||
bot.send_message(chat_id, message)
|
bot.send_message(chat_id, message, disable_web_page_preview=True)
|
||||||
sent_count += 1
|
sent_count += 1
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|||||||
Reference in New Issue
Block a user