From 54be5fa4d37425b37af173123cb05b47e9cb723a Mon Sep 17 00:00:00 2001 From: yshtcn Date: Fri, 13 Oct 2023 11:07:41 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=A9=BA=E5=80=BC=E6=9F=A5=E7=9C=8B=E4=BC=9A=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E7=9A=84bug=20-=20=E6=94=B9=E5=96=84=E4=BA=86?= =?UTF-8?q?=E6=89=93=E5=8C=85=E8=84=9A=E6=9C=AC=20-=20=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=E4=BA=86=E5=B8=AE=E5=8A=A9=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Diary Assistant_pyinstaller.bat | 8 ++++---- DiaryAssistant.py | 29 +++++++++++++++++------------ README.md | 6 +++--- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Diary Assistant_pyinstaller.bat b/Diary Assistant_pyinstaller.bat index 61a20b4..346233a 100644 --- a/Diary Assistant_pyinstaller.bat +++ b/Diary Assistant_pyinstaller.bat @@ -13,7 +13,7 @@ cls title "AutoPyInstaller:初始化" :: 让我们设置一些信息 -set "ProductName=Diary Assistant" +set "ProductName=DiaryAssistant_Bot" set "InternalName=yshtcn" set "Comments=GitHub: https://github.com/yshtcn/DiaryAssistant_bot" @@ -41,7 +41,7 @@ set "day=%datetime:~6,2%" set /p "revision=请输入今天的版本次:(%year%, %month%, %day%,[?]):" :: 当前版本目录(未去除先导0) -set "versionFolder=%year%_%month%_%day%_%revision%" +set "versionFolder=%ProductName%_Win_%year%_%month%_%day%_%revision%" :: 去除月和日的前导零(如果有) set /a "month=1%month%-100" @@ -100,7 +100,7 @@ md build rd /S /Q %~dp0\build\%versionFolder% :: 删除打包目录产生的过程文件 -del /q %~dp0\build\heartbeat.spec +del /q %~dp0\build\DiaryAssistant.spec rd /S /Q %~dp0\build\build :: 进入打包目录并开始打包 @@ -112,7 +112,7 @@ title "AutoPyInstaller :: (再次)删除打包目录下同版本号的文件夹 rd /S /Q %~dp0\build\%versionFolder% :: (再次)删除打包目录产生的过程文件 -del /q "%~dp0\build\Diary Assistant.spec" +del /q %~dp0\build\DiaryAssistant.spec rd /S /Q %~dp0\build\build :: 把生成打包的目录以版本号重命名 diff --git a/DiaryAssistant.py b/DiaryAssistant.py index 937b267..9568cf8 100644 --- a/DiaryAssistant.py +++ b/DiaryAssistant.py @@ -31,6 +31,7 @@ user_data_filename="user_data.json" # 妫鏌ラ厤缃枃浠舵槸鍚﹀瓨鍦 config_path = os.path.join(current_dir, config_filename) +print(f"Config file path: {config_path}") if os.path.exists(config_path): # 璇诲彇閰嶇疆鏂囦欢 @@ -60,7 +61,7 @@ else: } # 灏哻onfig瀵硅薄杞崲涓烘牸寮忓寲鐨凧SON瀛楃涓 config_str = json.dumps(config, indent=4) - + print(config_str) with open(config_path, 'w') as f: f.write(config_str) print(f"Config file created at {config_path}. Please set your bot token.") @@ -81,11 +82,22 @@ URL = f"https://api.telegram.org/bot{TOKEN}/" # 灏濊瘯浠庢枃浠朵腑鍔犺浇宸叉湁鏁版嵁 try: - with open(os.path.join(current_dir, config_filename), 'r') as f: + with open(os.path.join(current_dir, user_data_filename), 'r') as f: user_data = json.load(f) + print(f"User data loaded: {user_data}") except (FileNotFoundError, json.JSONDecodeError): + print("No user data found; starting with empty data.") user_data = {} +# 灏濊瘯浠庢枃浠朵腑鍔犺浇榛戝悕鍗 +try: + with open(os.path.join(current_dir, blacklist_filename), 'r') as f: + blacklist = json.load(f) + print(f"Blacklist loaded: {blacklist}") +except FileNotFoundError: + blacklist = [] + print("No blacklist found; starting with empty blacklist.") + def set_bot_commands(): try: set_commands_url = URL + "setMyCommands" @@ -107,14 +119,6 @@ def set_bot_commands(): return f"An error occurred: {err}" -# 灏濊瘯浠庢枃浠朵腑鍔犺浇榛戝悕鍗 -try: - with open(os.path.join(current_dir, blacklist_filename), 'r') as f: - blacklist = json.load(f) -except FileNotFoundError: - blacklist = [] - - # 鑾峰彇鏇存柊 def get_updates(offset=None): try: @@ -239,12 +243,13 @@ def main(): send_message(chat_id_str, f"#浜屾纭\n---\n浣犵湡鐨勮缁撴潫鏈璁板綍鍚楋紵纭璇风偣鍑伙細 /confirmdone \n濡傛灉涓嶆兂缁撴潫鏈璁板綍锛岀洿鎺ュ拷瑙嗚繖鏉′俊鎭佺户缁彂閫佷俊鎭垨浣跨敤鍏朵粬鎸囦护閮藉彲浠ャ") blacklist.append(unique_id) elif message_text.lower() == "/confirmdone": - main_text="\n\n".join(user_data[chat_id_str]) + main_text="\n\n".join(user_data.get(chat_id_str, [])) send_message(chat_id_str, f"#缁撴潫璁板綍\n浠ヤ笅鏄褰曠殑鍏ㄩ儴鍐呭锛歕n---\n```\n{main_text}\n```\n---\n涓嬫鍙戦佹秷鎭皢寮濮嬫柊鐨勮褰.") user_data[chat_id_str] = [] blacklist.append(unique_id) elif message_text.lower() == "/check": - main_text="\n\n".join(user_data[chat_id_str]) + print(f"user_data: {user_data}") + main_text="\n\n".join(user_data.get(chat_id_str, [])) send_message(chat_id_str, f"#鏌ョ湅璁板綍\n浠ヤ笅鏄凡璁板綍鐨勫叏閮ㄥ唴瀹癸細\n---\n```\n{main_text}\n```\n---\n鍙戦佹秷鎭皢缁х画褰撳墠鐨勮褰.") blacklist.append(unique_id) elif message_text.lower() == "/removelast": diff --git a/README.md b/README.md index b60dc6b..d5559df 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,11 @@ ## 涓轰粈涔堣鍒朵綔杩欎釜bot锛 -鍘熷洜寰堢畝鍗曪紝鍥犱负AI鏃ヨ鐨勫叴璧封斺斺斺旀垜浠彲浠ユ妸AI褰撴垚鏈嬪弸涓鏍蜂笉鏂殑璇夎锛屾渶鍚庤AI鍥為【鏁寸悊涓澶╃殑浜嬫儏鎴愪负鏃ヨ銆傛渶鍒濇垜鏄娇鐢╟hatGPT瀹屾垚杩欎竴鐐圭殑锛屼絾鏄缁堝湪AI鐨勭晫闈㈣繘琛屽璇濆崄鍒嗕笉渚匡紝鑰屼笖GPT鐨勫璇濇鏁版槸鏈夐檺鐨勶紝鏈夋椂鍊欏お纰庣蹇典細閫犳垚瀵硅瘽娆℃暟鍙楅檺銆備簬鏄垜璁捐銆佸紑鍙戜簡杩欎釜bot銆 +鍘熷洜寰堢畝鍗曪紝鍥犱负AI鏃ヨ鐨勫叴璧封斺斺斺旀垜浠彲浠ユ妸AI褰撴垚鏈嬪弸涓鏍蜂笉鏂殑璇夎锛屾渶鍚庤AI鍥為【鏁寸悊涓澶╃殑浜嬫儏鎴愪负鏃ヨ銆傚綋鐒讹紝浣犱篃鍙互鐢ㄦ潵鏀堕泦涓浜涚鐗囧寲鐨勪俊鎭傛渶鍒濇垜鏄娇鐢╟hatGPT瀹屾垚杩欎竴鐐圭殑锛屼絾鏄缁堝湪AI鐨勭晫闈㈣繘琛屽璇濆崄鍒嗕笉渚匡紝鑰屼笖GPT鐨勫璇濇鏁版槸鏈夐檺鐨勶紝鏈夋椂鍊欏お纰庣蹇典細閫犳垚瀵硅瘽娆℃暟鍙楅檺銆備簬鏄垜璁捐銆佸紑鍙戜簡杩欎釜bot銆 ## 涓轰粈涔堣寮婧愬彂甯冭屼笉鏄洿鎺ユ彁渚沚ot锛 -棣栧厛鏃ヨ杩欎釜涓滆タ寰堢瀵嗭紝浣犱笉鐭ラ亾bot鎴栬呭叾浠栬蒋浠剁殑鍙︿竴绔湁璋佸湪鐩潃锛屾垜寤鸿杩樻槸鍦ㄨ嚜宸辩殑鐢佃剳/鏈嶅姟鍣ㄤ笂璺戝ソ涓鐐广 +棣栧厛浣犳敹闆嗙殑涓滆タ鍙兘寰堢瀵嗭紝浣犱笉鐭ラ亾bot鎴栬呭叾浠栬蒋浠剁殑鍙︿竴绔湁璋佸湪鐩潃锛屾垜寤鸿杩樻槸鍦ㄨ嚜宸辩殑鐢佃剳/鏈嶅姟鍣ㄤ笂璺戝ソ涓鐐广 # 浣跨敤鏂规硶 @@ -29,5 +29,5 @@ - 鎶/mydata鎹㈡垚鏄犲皠鐨勭洰鐨勮矾寰勶紝棣栨杩愯鏃讹紝浼氳嚜鍔ㄧ敓鎴恇ot_config.json锛屽苟鑷姩閫鍑恒 - 鐒跺悗鎶婁綘鐨刡otid濉繘鏄犲皠鐩殑鍦板潃涓嬬殑bot_config.json锛屽苟閰嶇疆濂戒唬鐞嗗湴鍧锛堝鏋滀笉闇瑕佷唬鐞嗗湴鍧锛岀洿鎺ュ垹闄や唬鐞嗕俊鎭嵆鍙級銆 - - 娉ㄦ剰锛屽鏋滀綘鏃犳硶缂栬緫鏂囦欢锛屽彲鑳介渶瑕佺粰涓庢潈闄:```chmod -R 777 /mydata``` + - 娉ㄦ剰锛屽鏋滀綘鏃犳硶缂栬緫鏂囦欢锛屽彲鑳借缁欎笌鏉冮檺:```chmod -R 777 /mydata``` - 鍐嶆鍚姩锛屽悜浣犵殑bot鍙戦/start鐪嬬湅鏄惁鍙互姝e父杩愯灏卞彲浠ヤ簡銆