mirror of
https://github.com/yshtcn/ServerChanPush2TelegramBot.git
synced 2025-12-11 16:50:22 +08:00
- 完善了TestStatus=4的功能(为了兼容性,保留了TestStatus=3一次性重试发送所有内容的功能,但建议迁移到4上)
- 去掉了发新消息成功时,自动重试旧消息,以后旧消息建议全部通过TestStatus=4重发。 TestStatus=4功能说明: 被访问时,从待发送列表中,每次尝试重发10条。并返回成功发送数和剩余消息数。 我们可以借助外部定期访问,实现监测和自动重发的双重目的。
This commit is contained in:
parent
c63073970a
commit
d218bcf1d8
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user