Fix monitor message id recording
This commit is contained in:
@@ -142,6 +142,8 @@ touch tg-watchbot.sqlite3 tg-watchbot.log
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
Docker 会在容器内监听 `0.0.0.0:8765`,宿主机仍然打开 `http://127.0.0.1:8765`。
|
||||
|
||||
查看状态与日志:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -463,7 +463,8 @@ async def admin_send_monitor(text: str, monitor_name: str) -> bool:
|
||||
sent = await bot.send_message(chat_id, text, disable_web_page_preview=False)
|
||||
settings = monitor_cleanup_settings()
|
||||
record_monitor_message(
|
||||
sent,
|
||||
chat_id,
|
||||
sent.message_id,
|
||||
monitor_name,
|
||||
int(settings["message_delete_after_minutes"]) * 60,
|
||||
)
|
||||
@@ -974,7 +975,8 @@ def event_not_sent(event_key: str, monitor_name: str, title: str, link: str) ->
|
||||
|
||||
|
||||
def record_monitor_message(
|
||||
sent_message: Message,
|
||||
chat_id: int,
|
||||
message_id: int,
|
||||
monitor_name: str,
|
||||
delete_after_seconds: int,
|
||||
sent_at_ts: float | None = None,
|
||||
@@ -989,8 +991,8 @@ def record_monitor_message(
|
||||
) VALUES(?,?,?,?,?,NULL)
|
||||
""",
|
||||
(
|
||||
sent_message.chat.id,
|
||||
sent_message.message_id,
|
||||
chat_id,
|
||||
message_id,
|
||||
monitor_name,
|
||||
sent_at,
|
||||
max(1, int(delete_after_seconds)),
|
||||
|
||||
@@ -7,6 +7,8 @@ services:
|
||||
- "8765:8765"
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
WEB_PANEL_HOST: 0.0.0.0
|
||||
volumes:
|
||||
- ./config.yaml:/app/config.yaml
|
||||
- ./tg-watchbot.sqlite3:/app/tg-watchbot.sqlite3
|
||||
|
||||
@@ -89,7 +89,7 @@ class FakeBot:
|
||||
raise RuntimeError("send failed")
|
||||
self.sent_chat_ids.append(chat_id)
|
||||
self.sent_texts.append(text)
|
||||
return SimpleNamespace(chat=SimpleNamespace(id=chat_id), message_id=3003)
|
||||
return SimpleNamespace(message_id=3003)
|
||||
|
||||
|
||||
class MonitorMessageCleanupTest(unittest.TestCase):
|
||||
@@ -185,8 +185,7 @@ class MonitorMessageCleanupTest(unittest.TestCase):
|
||||
self.assertEqual((1001, 3003, 2001, 4004), row)
|
||||
|
||||
def test_expired_monitor_message_is_deleted_and_removed_from_queue(self) -> None:
|
||||
sent_message = SimpleNamespace(chat=SimpleNamespace(id=1001), message_id=2002)
|
||||
app.record_monitor_message(sent_message, "NodeSeek 新帖", delete_after_seconds=60, sent_at_ts=1000)
|
||||
app.record_monitor_message(1001, 2002, "NodeSeek 新帖", delete_after_seconds=60, sent_at_ts=1000)
|
||||
|
||||
fake_bot = FakeBot()
|
||||
deleted_count = asyncio.run(app.delete_expired_monitor_messages(fake_bot, now_ts=1061))
|
||||
@@ -198,8 +197,7 @@ class MonitorMessageCleanupTest(unittest.TestCase):
|
||||
self.assertEqual(0, remaining)
|
||||
|
||||
def test_unexpired_monitor_message_is_kept(self) -> None:
|
||||
sent_message = SimpleNamespace(chat=SimpleNamespace(id=1001), message_id=2002)
|
||||
app.record_monitor_message(sent_message, "NodeSeek 新帖", delete_after_seconds=60, sent_at_ts=1000)
|
||||
app.record_monitor_message(1001, 2002, "NodeSeek 新帖", delete_after_seconds=60, sent_at_ts=1000)
|
||||
|
||||
fake_bot = FakeBot()
|
||||
deleted_count = asyncio.run(app.delete_expired_monitor_messages(fake_bot, now_ts=1059))
|
||||
|
||||
Reference in New Issue
Block a user