From 5902f188197614def981bc8c0e298a2eeb654bf6 Mon Sep 17 00:00:00 2001 From: yshtcn Date: Thu, 21 Sep 2023 15:46:54 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复了存在多个同样id的问题 - 调整了回复的样式 - 最后的结束语句是/done - 成功收到数据会循环把信息发出去,每次结束时还会补发。 --- Diary Assistant.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Diary Assistant.py b/Diary Assistant.py index 9fe356b..5658da5 100644 --- a/Diary Assistant.py +++ b/Diary Assistant.py @@ -145,18 +145,23 @@ def main(): + chat_id_str = str(chat_id) + if unique_id not in blacklist: # 处理“done”命令 - if message_text.lower() == "/todaydone": - send_message(chat_id, "\n".join(user_data[chat_id])) - user_data[chat_id] = [] + if message_text.lower() == "/done": + send_message(chat_id_str, "\n\n".join(user_data[chat_id_str])) + user_data[chat_id_str] = [] + blacklist.append(unique_id) else: - send_message(chat_id, f"{message_text_with_datetime}") - if chat_id not in user_data: - user_data[chat_id] = [] - user_data[chat_id].append(message_text) + send_message(chat_id_str, f"{message_text_with_datetime}") + if chat_id_str not in user_data: + user_data[chat_id_str] = [] + user_data[chat_id_str].append(message_text) blacklist.append(unique_id) # 添加到黑名单 + + # 保存数据到文件 with open('user_data.json', 'w') as f: json.dump(user_data, f) @@ -170,13 +175,15 @@ def main(): with open('blacklist.json', 'w') as f: json.dump(blacklist, f) - process_message_queue() + print("process message queue...") + process_message_queue() else: - print(f"{URL}Received updates: {updates}") + print(f"{URL} Received updates: {updates}") print("Error or no updates; retrying in 5 seconds...") time.sleep(5) # 等待5秒再重试 - + print("process message queue...") + process_message_queue() # 每1分钟检查一次 time.sleep(15)