From d218bcf1d810d55ce126f51935b11bd1d106d430 Mon Sep 17 00:00:00 2001 From: yshtcn Date: Sun, 24 Nov 2024 08:02:38 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=AE=8C=E5=96=84=E4=BA=86TestStatus=3D4?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=88=E4=B8=BA=E4=BA=86=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7=EF=BC=8C=E4=BF=9D=E7=95=99=E4=BA=86TestStatu?= =?UTF-8?q?s=3D3=E4=B8=80=E6=AC=A1=E6=80=A7=E9=87=8D=E8=AF=95=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=89=80=E6=9C=89=E5=86=85=E5=AE=B9=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=BD=86=E5=BB=BA=E8=AE=AE=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=88=B04=E4=B8=8A=EF=BC=89=20-=20=E5=8E=BB=E6=8E=89=E4=BA=86?= =?UTF-8?q?=E5=8F=91=E6=96=B0=E6=B6=88=E6=81=AF=E6=88=90=E5=8A=9F=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E5=8A=A8=E9=87=8D=E8=AF=95=E6=97=A7=E6=B6=88?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E4=BB=A5=E5=90=8E=E6=97=A7=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE=E5=85=A8=E9=83=A8=E9=80=9A=E8=BF=87TestStatu?= =?UTF-8?q?s=3D4=E9=87=8D=E5=8F=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestStatus=4功能说明: 被访问时,从待发送列表中,每次尝试重发10条。并返回成功发送数和剩余消息数。 我们可以借助外部定期访问,实现监测和自动重发的双重目的。 --- ServerChanPush2TelegramBot.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ServerChanPush2TelegramBot.py b/ServerChanPush2TelegramBot.py index 3e1178b..1427fee 100644 --- a/ServerChanPush2TelegramBot.py +++ b/ServerChanPush2TelegramBot.py @@ -301,6 +301,19 @@ def index(): else: return jsonify({"ok": "no pending messages to re-send", "pending_messages_count": pending_count}), 200 elif TestStatus == '4': + # 读取当前待发送消息数量 + pending_messages = read_pending_messages() + pending_count = len(pending_messages) + + if pending_count == 0: + # 如果没有待发送消息,直接返回与 TestStatus == '3' 一致的结构 + return jsonify({ + "ok": "no pending messages to re-send", + "pending_messages_count": pending_count, + "remaining_pending_messages_count": 0, + "successfully_sent_count": 0 + }), 200 + # 调用批量发送逻辑,每次最多发送10条 result = send_messages_in_batches(batch_size=10) @@ -308,27 +321,28 @@ def index(): remaining_messages = read_pending_messages() remaining_count = len(remaining_messages) - # 返回结果中包含剩余待发送消息数量 + # 返回结果与 TestStatus == '3' 保持一致,并增加成功发送条数 return jsonify({ "ok": "batch processed", - "successfully_sent_count": result["successfully_sent_count"], + "pending_messages_count": pending_count, "remaining_pending_messages_count": remaining_count, - "message": result["message"] + "successfully_sent_count": result["successfully_sent_count"] }), 200 + # 原始的消息发送逻辑 pending_messages = read_pending_messages() success, response = send_telegram_message(bot_id, chat_id, title, desp, url) if success: - new_pending_messages = [] - for msg in pending_messages: - success, _ = send_telegram_message(msg['bot_id'], msg['chat_id'], msg['title'], msg['desp'], msg.get('url')) - if not success: - new_pending_messages.append(msg) - # 更新待发送消息列表,只包含失败的消息 - write_pending_messages(new_pending_messages) + # new_pending_messages = [] + # for msg in pending_messages: + # success, _ = send_telegram_message(msg['bot_id'], msg['chat_id'], msg['title'], msg['desp'], msg.get('url')) + # if not success: + # new_pending_messages.append(msg) + # # 更新待发送消息列表,只包含失败的消息 + # write_pending_messages(new_pending_messages) return jsonify(response), 200 else: if "【This is a delayed message】" not in desp: