From e1741f5ea31ec8384ad1f4fe3355c9461e091f99 Mon Sep 17 00:00:00 2001 From: jiajiu123 <1771663559@qq.com> Date: Sat, 8 Mar 2025 04:17:08 +0800 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20ignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 4 +++- .gitignore | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 0ed9090fd..6c2d07736 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,6 @@ __pycache__ *.pyc *.pyo *.pyd -.DS_Store \ No newline at end of file +.DS_Store +mongodb +napcat \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7eba6537c..3f6ad3edd 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,8 @@ __pycache__/ *.py[cod] *$py.class llm_statistics.txt +mongodb +napcat # C extensions *.so From a0220ff581b341cde7986e13803aa4691f8327dc Mon Sep 17 00:00:00 2001 From: jiajiu123 <1771663559@qq.com> Date: Sat, 8 Mar 2025 04:17:22 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20Windows=20=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.bat | 6 +++ run.py | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 run.bat create mode 100644 run.py diff --git a/run.bat b/run.bat new file mode 100644 index 000000000..1d1385671 --- /dev/null +++ b/run.bat @@ -0,0 +1,6 @@ +@ECHO OFF +chcp 65001 +REM python -m venv venv +call venv\Scripts\activate.bat +REM pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple --upgrade -r requirements.txt +python run.py \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 000000000..d8513beed --- /dev/null +++ b/run.py @@ -0,0 +1,122 @@ +import subprocess +import os +import shutil +import zipfile +import requests +from tqdm import tqdm + + +def extract_files(zip_path, target_dir): + """ + 解压 + + Args: + zip_path: 源ZIP压缩包路径(需确保是有效压缩包) + target_dir: 目标文件夹路径(会自动创建不存在的目录) + """ + # 打开ZIP压缩包(上下文管理器自动处理关闭) + with zipfile.ZipFile(zip_path) as zip_ref: + # 通过第一个文件路径推断顶层目录名(格式如:top_dir/) + top_dir = zip_ref.namelist()[0].split("/")[0] + "/" + + # 遍历压缩包内所有文件条目 + for file in zip_ref.namelist(): + # 跳过目录条目,仅处理文件 + if file.startswith(top_dir) and not file.endswith("/"): + # 截取顶层目录后的相对路径(如:sub_dir/file.txt) + rel_path = file[len(top_dir) :] + + # 创建目标目录结构(含多级目录) + os.makedirs( + os.path.dirname(f"{target_dir}/{rel_path}"), + exist_ok=True, # 忽略已存在目录的错误 + ) + + # 读取压缩包内文件内容并写入目标路径 + with open(f"{target_dir}/{rel_path}", "wb") as f: + f.write(zip_ref.read(file)) + + +def run_cmd(command: str, open_new_window: bool = False): + """ + 运行 cmd 命令 + + Args: + command (str): 指定要运行的命令 + open_new_window (bool): 指定是否新建一个 cmd 窗口运行 + """ + creationflags = 0 + if open_new_window: + creationflags = subprocess.CREATE_NEW_CONSOLE + subprocess.Popen( + [ + "cmd.exe", + "/c", + command, + ], + creationflags=creationflags, + ) + + +def run_maimbot(): + run_cmd(r"napcat\NapCatWinBootMain.exe 10001", False) + run_cmd( + r"mongodb\bin\mongod.exe --dbpath=" + os.getcwd() + r"\mongodb\db --port 27017", + True, + ) + run_cmd("nb run", True) + + +def install_mongodb(): + """ + 安装 MongoDB + """ + print("下载 MongoDB") + resp = requests.get( + "https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-latest.zip", + stream=True, + ) + total = int(resp.headers.get("content-length", 0)) # 计算文件大小 + with open("mongodb.zip", "w+b") as file, tqdm( # 展示下载进度条,并解压文件 + desc="mongodb.zip", + total=total, + unit="iB", + unit_scale=True, + unit_divisor=1024, + ) as bar: + for data in resp.iter_content(chunk_size=1024): + size = file.write(data) + bar.update(size) + extract_files("mongodb.zip", "mongodb") + print("MongoDB 下载完成") + os.remove("mongodb.zip") + + +def install_napcat(): + run_cmd("start https://github.com/NapNeko/NapCatQQ/releases", True) + print("请检查弹出的浏览器窗口,点击**第一个**蓝色的“Win64无头” 下载 napcat") + napcat_filename = input( + "下载完成后请把文件复制到此文件夹,并将**不包含后缀的文件名**输入至此窗口,如 NapCat.32793.Shell:" + ) + extract_files(napcat_filename + ".zip", "napcat") + print("NapCat 安装完成") + os.remove(napcat_filename + ".zip") + + +if __name__ == "__main__": + os.system("cls") + choice = input( + "请输入要进行的操作:\n" + "1.首次安装\n" + "2.运行麦麦\n" + "3.运行麦麦并启动可视化推理界面\n" + ) + os.system("cls") + if choice == "1": + install_napcat() + install_mongodb() + elif choice == "2": + run_maimbot() + elif choice == "3": + run_maimbot() + run_cmd("python src/gui/reasoning_gui.py", True) From bb104d65a1a983398764c28d75de083b0bab564c Mon Sep 17 00:00:00 2001 From: jiajiu123 <1771663559@qq.com> Date: Sat, 8 Mar 2025 04:17:41 +0800 Subject: [PATCH 3/5] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flagged/log.csv | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 flagged/log.csv diff --git a/flagged/log.csv b/flagged/log.csv deleted file mode 100644 index daeef4a9b..000000000 --- a/flagged/log.csv +++ /dev/null @@ -1,2 +0,0 @@ -输入消息,推理内容,flag,username,timestamp -显示内容,,,,2025-02-18 16:50:53.643238 From ebb633770a894ea55e10e605ccbaae033533ffd7 Mon Sep 17 00:00:00 2001 From: jiajiu123 <1771663559@qq.com> Date: Sat, 8 Mar 2025 04:24:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20toml=20=E6=96=87=E4=BB=B6=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=87=BA=E9=94=99=E6=97=B6=E6=8F=90=E9=86=92=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/chat/config.py b/src/plugins/chat/config.py index 0186001ab..6ebf5b165 100644 --- a/src/plugins/chat/config.py +++ b/src/plugins/chat/config.py @@ -85,7 +85,11 @@ class BotConfig: config = cls() if os.path.exists(config_path): with open(config_path, "rb") as f: - toml_dict = tomli.load(f) + try: + toml_dict = tomli.load(f) + except(tomli.TOMLDecodeError) as e: + logger.critical(f"配置文件bot_config.toml填写有误,请检查第{e.lineno}行第{e.colno}处:{e.msg}") + exit(1) if 'personality' in toml_dict: personality_config=toml_dict['personality'] From 2743847776f87c36344e3d53165e3b7a85640699 Mon Sep 17 00:00:00 2001 From: jiajiu123 <1771663559@qq.com> Date: Sat, 8 Mar 2025 04:26:05 +0800 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20=E7=A7=BB=E5=8A=A8=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=84=9A=E6=9C=AC=E8=87=B3=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_db.bat => script/run_db.bat | 0 run_maimai.bat => script/run_maimai.bat | 0 run_thingking.bat => script/run_thingking.bat | 0 run_windows.bat => script/run_windows.bat | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename run_db.bat => script/run_db.bat (100%) rename run_maimai.bat => script/run_maimai.bat (100%) rename run_thingking.bat => script/run_thingking.bat (100%) rename run_windows.bat => script/run_windows.bat (100%) diff --git a/run_db.bat b/script/run_db.bat similarity index 100% rename from run_db.bat rename to script/run_db.bat diff --git a/run_maimai.bat b/script/run_maimai.bat similarity index 100% rename from run_maimai.bat rename to script/run_maimai.bat diff --git a/run_thingking.bat b/script/run_thingking.bat similarity index 100% rename from run_thingking.bat rename to script/run_thingking.bat diff --git a/run_windows.bat b/script/run_windows.bat similarity index 100% rename from run_windows.bat rename to script/run_windows.bat