Add local peak timing and /markets bot digest

This commit is contained in:
2569718930@qq.com
2026-04-01 18:24:50 +08:00
parent 07b2770e9d
commit c9719cf577
8 changed files with 192 additions and 45 deletions
+25
View File
@@ -9,6 +9,7 @@ from src.bot.observability import CommandTrace
from src.bot.runtime_coordinator import RuntimeStatus, render_runtime_status_html
_BASIC_COMMANDS = {"start", "help", "id", "top", "diag", "bind", "unbind"}
_BASIC_COMMANDS = {"start", "help", "id", "top", "diag", "bind", "unbind", "markets"}
class BasicCommandHandler:
@@ -17,10 +18,12 @@ class BasicCommandHandler:
bot: Any,
io_layer: BotIOLayer,
runtime_status_provider: Callable[[], RuntimeStatus],
config: dict | None = None,
):
self.bot = bot
self.io_layer = io_layer
self.runtime_status_provider = runtime_status_provider
self.config = config or {}
def register(self) -> None:
@self.bot.message_handler(commands=["start", "help"])
@@ -47,6 +50,10 @@ class BasicCommandHandler:
def _unbind(message):
self._dispatch(message)
@self.bot.message_handler(commands=["markets"])
def _markets(message):
self._dispatch(message)
@self.bot.message_handler(
content_types=["text"],
func=lambda message: extract_command_name(
@@ -87,6 +94,9 @@ class BasicCommandHandler:
if command == "unbind":
self.handle_unbind(message)
return
if command == "markets":
self.handle_markets(message)
return
def handle_start_help(self, message: Any) -> None:
trace = CommandTrace("/start", message)
@@ -233,3 +243,18 @@ class BasicCommandHandler:
trace.set_status("ok", "unbound")
finally:
trace.emit()
def handle_markets(self, message: Any) -> None:
trace = CommandTrace("/markets", message)
try:
from src.utils.telegram_push import build_market_monitor_digest
summary = build_market_monitor_digest(
self.config,
slot_label="当前市场概览",
force_refresh=False,
)
self.bot.reply_to(message, summary)
trace.set_status("ok")
finally:
trace.emit()
+1
View File
@@ -178,6 +178,7 @@ class BotIOLayer:
"可用指令:\n"
f"/city [城市名] 或 /pwcity [城市名] - 查询城市天气预测与实测 (消耗 {CITY_QUERY_COST} 积分)\n"
f"/deb [城市名] 或 /pwdeb [城市名] - 查看 DEB 融合预测准确率 (消耗 {DEB_QUERY_COST} 积分)\n"
"/markets - 查看当前市场监控摘要\n"
"/top - 查看积分排行榜\n"
"/id - 获取当前聊天的 Chat ID\n\n"
"/diag - 查看 Bot 启动诊断\n\n"
+1
View File
@@ -36,6 +36,7 @@ def _register_handlers(
bot=bot,
io_layer=io_layer,
runtime_status_provider=startup_coordinator.get_runtime_status,
config=config,
).register()
CityCommandHandler(
bot=bot,
+1 -1
View File
@@ -169,7 +169,7 @@ class StartupCoordinator:
"focus_digest_hours": str(
os.getenv("TELEGRAM_MARKET_FOCUS_DIGEST_HOURS") or "11,18"
).strip(),
"timezone": str(os.getenv("TELEGRAM_MARKET_TIMEZONE") or "Asia/Shanghai").strip(),
"schedule_basis": "server_local_time",
}
validation_error = None if chat_ids else "missing_TELEGRAM_CHAT_IDS"
return self._start_with_validation(