From d53c321d4142254a07ecc8051ade3716e05b9401 Mon Sep 17 00:00:00 2001 From: KawaiiYusora Date: Thu, 13 Mar 2025 18:53:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0MaiLauncher.bat?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BB=A5=E5=90=AF=E5=8A=A8=E5=92=8C=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=BA=A6=E9=BA=A6Bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MaiLauncher.bat | 303 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 MaiLauncher.bat diff --git a/MaiLauncher.bat b/MaiLauncher.bat new file mode 100644 index 000000000..2b3e3d819 --- /dev/null +++ b/MaiLauncher.bat @@ -0,0 +1,303 @@ +@echo off +@REM setlocal enabledelayedexpansion +@chcp 65001 + +@REM 设置版本号 +set "VERSION=0.3" + +title 麦麦Bot控制台 v%VERSION% + +@REM 设置Python和Git环境变量 +set "_root=%~dp0" +set "_root=%_root:~0,-1%" +cd "%_root%" +echo "%_root% + +if exist "%_root%\python" ( + set "PYTHON_HOME=%_root%\python" +) else if exist "%_root%\venv" ( + call "%_root%\venv\Scripts\activate.bat" + set "PYTHON_HOME=%_root%\venv\Scripts" +) else if python -V >nul 2>&1 ( + for /f "delims=" %%a in ('where python') do ( + set "PYTHON_HOME=%%~dpa" + ) +) else if python3 -V >nul 2>&1 ( + for /f "delims=" %%a in ('where python3') do ( + set "PYTHON_HOME=%%~dpa" + ) +) else ( + echo Python环境未找到,请检查安装路径。 + exit /b +) + +if exist "%_root%\tools\git\bin" ( + set "GIT_HOME=%_root%\tools\git\bin" +) else if git -v >nul 2>&1 ( + for /f "delims=" %%a in ('where git') do ( + set "GIT_HOME=%%~dpa" + ) +) else ( + echo Git环境未找到,请检查安装路径。 + exit /b +) + + +set "GIT_HOME=%_root%\tools\git\bin" +set "PATH=%PYTHON_HOME%;%GIT_HOME%;%PATH%" + + +@REM git获取当前分支名并保存在变量里 +for /f "delims=" %%b in ('git symbolic-ref --short HEAD 2^>nul') do ( + set "BRANCH=%%b" +) + +@REM 根据不同分支名给分支名字符串使用不同颜色 +echo 分支名: %BRANCH% +if "%BRANCH%"=="main" ( + set "BRANCH_COLOR=" +) else if "%BRANCH%"=="debug" ( + set "BRANCH_COLOR=" +) else if "%BRANCH%"=="stable-dev" ( + set "BRANCH_COLOR=" +) else ( + set "BRANCH_COLOR=" +) + +@REM endlocal & set "BRANCH_COLOR=%BRANCH_COLOR%" + + +:menu +@chcp 65001 +cls +echo 麦麦Bot控制台 v%VERSION% 当前分支: %BRANCH_COLOR%%BRANCH% +echo ====================== +echo 1. 更新并启动麦麦Bot (默认) +echo 2. 直接启动麦麦Bot +echo 3. 麦麦配置菜单 +echo 4. 麦麦神奇工具箱 +echo 5. 退出 +echo ====================== + +set /p choice="请输入选项数字 (1-5)并按下回车以选择: " + +if "%choice%"=="" set choice=1 + +if "%choice%"=="1" goto update_and_start +if "%choice%"=="2" goto start_bot +if "%choice%"=="3" goto config_menu +if "%choice%"=="4" goto tools_menu +if "%choice%"=="5" exit /b + +echo 无效的输入,请输入1-5之间的数字 +timeout /t 2 >nul +goto menu + +:config_menu +@chcp 65001 +cls +echo 配置菜单 +echo ====================== +echo 1. 编辑配置文件 (config.toml) +echo 2. 编辑环境变量 (.env.prod) +echo 3. 打开安装目录 +echo 4. 返回主菜单 +echo ====================== + +set /p choice="请输入选项数字: " + +if "%choice%"=="1" goto edit_config +if "%choice%"=="2" goto edit_env +if "%choice%"=="3" goto open_dir +if "%choice%"=="4" goto menu + +echo 无效的输入,请输入1-4之间的数字 +timeout /t 2 >nul +goto config_menu + +:tools_menu +@chcp 65001 +cls +echo 麦麦时尚工具箱 当前分支: %BRANCH_COLOR%%BRANCH% +echo ====================== +echo 1. 更新依赖 +echo 2. 切换分支 +echo 3. 更新配置文件 +echo 4. 学习新的知识库 +echo 5. 打开知识库文件夹 +echo 6. 返回主菜单 +echo ====================== + +set /p choice="请输入选项数字: " +if "%choice%"=="1" goto update_dependencies +if "%choice%"=="2" goto switch_branch +if "%choice%"=="3" goto update_config +if "%choice%"=="4" goto learn_new_knowledge +if "%choice%"=="5" goto open_knowledge_folder +if "%choice%"=="6" goto menu + +echo 无效的输入,请输入1-6之间的数字 +timeout /t 2 >nul +goto tools_menu + +:update_dependencies +cls +echo 正在更新依赖... +python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple +python.exe -m pip install -r requirements.txt + +echo 依赖更新完成,按任意键返回工具箱菜单... +pause +goto tools_menu + +:switch_branch +cls +echo 正在切换分支... +echo 当前分支: %BRANCH% +echo 可用分支: main, debug, stable-dev +echo 请输入要切换到的分支名 (main/debug/stable-dev): +set /p branch_name="分支名: " +if "%branch_name%"=="" set branch_name=main +if "%branch_name%"=="main" ( + set "BRANCH_COLOR=" +) else if "%branch_name%"=="debug" ( + set "BRANCH_COLOR=" +) else if "%branch_name%"=="stable-dev" ( + set "BRANCH_COLOR=" +) else ( + echo 无效的分支名, 请重新输入 + timeout /t 2 >nul + goto switch_branch +) + +echo 正在切换到分支 %branch_name%... +git checkout %branch_name% +echo 分支切换完成,当前分支: %BRANCH_COLOR%%branch_name% +set "BRANCH=%branch_name%" +echo 按任意键返回工具箱菜单... +pause >nul +goto tools_menu + + +:update_config +cls +echo 正在更新配置文件... +echo 请确保已备份重要数据,继续将修改当前配置文件。 +echo 继续请按Y,取消请按任意键... +set /p confirm="继续?(Y/N): " +if /i "%confirm%"=="Y" ( + echo 正在更新配置文件... + python\python.exe config\auto_update.py + echo 配置文件更新完成,按任意键返回工具箱菜单... +) else ( + echo 取消更新配置文件,按任意键返回工具箱菜单... +) +pause >nul +goto tools_menu + +:learn_new_knowledge +cls +echo 正在学习新的知识库... +echo 请确保已备份重要数据,继续将修改当前知识库。 +echo 继续请按Y,取消请按任意键... +set /p confirm="继续?(Y/N): " +if /i "%confirm%"=="Y" ( + echo 正在学习新的知识库... + python\python.exe src\plugins\zhishi\knowledge_library.py + echo 学习完成,按任意键返回工具箱菜单... +) else ( + echo 取消学习新的知识库,按任意键返回工具箱菜单... +) +pause >nul +goto tools_menu + +:open_knowledge_folder +cls +echo 正在打开知识库文件夹... +if exist data\raw_info ( + start explorer data\raw_info +) else ( + echo 知识库文件夹不存在! + echo 正在创建文件夹... + mkdir data\raw_info + timeout /t 2 >nul +) +goto tools_menu + + +:update_and_start +cls +:retry_git_pull +tools\git\bin\git.exe pull > temp.log 2>&1 +findstr /C:"detected dubious ownership" temp.log >nul +if %errorlevel% equ 0 ( + echo 检测到仓库权限问题,正在自动修复... + tools\git\bin\git.exe config --global --add safe.directory "%cd%" + echo 已添加例外,正在重试git pull... + del temp.log + goto retry_git_pull +) +del temp.log +echo 正在更新依赖... +python\python.exe -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple +python\python.exe -m pip install -r requirements.txt && cls + +echo 当前代理设置: +echo HTTP_PROXY=%HTTP_PROXY% +echo HTTPS_PROXY=%HTTPS_PROXY% + +echo Disable Proxy... +set HTTP_PROXY= +set HTTPS_PROXY= +set no_proxy=0.0.0.0/32 + +REM chcp 65001 +python\python.exe bot.py +echo. +echo Bot已停止运行,按任意键返回主菜单... +pause >nul +goto menu + +:start_bot +cls +echo 正在更新依赖... +python\python.exe -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple +python\python.exe -m pip install -r requirements.txt && cls + +echo 当前代理设置: +echo HTTP_PROXY=%HTTP_PROXY% +echo HTTPS_PROXY=%HTTPS_PROXY% + +echo Disable Proxy... +set HTTP_PROXY= +set HTTPS_PROXY= +set no_proxy=0.0.0.0/32 + +REM chcp 65001 +python\python.exe bot.py +echo. +echo Bot已停止运行,按任意键返回主菜单... +pause >nul +goto menu + +:edit_config +if exist config/bot_config.toml ( + start notepad config/bot_config.toml +) else ( + echo 配置文件 bot_config.toml 不存在! + timeout /t 2 >nul +) +goto menu + +:edit_env +if exist .env.prod ( + start notepad .env.prod +) else ( + echo 环境文件 .env.prod 不存在! + timeout /t 2 >nul +) +goto menu + +:open_dir +start explorer "%cd%" +goto menu From f38be09835126fb3de0c5a3e14ce631c3ed5f341 Mon Sep 17 00:00:00 2001 From: KawaiiYusora Date: Sat, 15 Mar 2025 06:20:00 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20feat(MaiLauncher.bat):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96Python=E5=92=8CGit=E7=8E=AF=E5=A2=83=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=AE=89=E8=A3=85=E5=92=8C=E8=B7=AF=E5=BE=84=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=20=F0=9F=94=A7=20fix(MaiLauncher.bat):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=88=86=E6=94=AF=E5=88=87=E6=8D=A2=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=97=A0=E6=95=88=E5=88=86=E6=94=AF?= =?UTF-8?q?=E9=80=89=E9=A1=B9=20=F0=9F=93=9D=20docs(MaiLauncher.bat):=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=8F=9C=E5=8D=95=E9=80=89=E9=A1=B9=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=EF=BC=8C=E7=AE=80=E5=8C=96=E9=85=8D=E7=BD=AE=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MaiLauncher.bat | 261 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 191 insertions(+), 70 deletions(-) diff --git a/MaiLauncher.bat b/MaiLauncher.bat index 2b3e3d819..9d2b5965e 100644 --- a/MaiLauncher.bat +++ b/MaiLauncher.bat @@ -1,6 +1,6 @@ @echo off -@REM setlocal enabledelayedexpansion -@chcp 65001 +setlocal enabledelayedexpansion +@chcp 936 @REM 设置版本号 set "VERSION=0.3" @@ -13,39 +13,175 @@ set "_root=%_root:~0,-1%" cd "%_root%" echo "%_root% +:search_python if exist "%_root%\python" ( set "PYTHON_HOME=%_root%\python" ) else if exist "%_root%\venv" ( call "%_root%\venv\Scripts\activate.bat" set "PYTHON_HOME=%_root%\venv\Scripts" -) else if python -V >nul 2>&1 ( - for /f "delims=" %%a in ('where python') do ( - set "PYTHON_HOME=%%~dpa" - ) -) else if python3 -V >nul 2>&1 ( - for /f "delims=" %%a in ('where python3') do ( - set "PYTHON_HOME=%%~dpa" - ) ) else ( - echo Python环境未找到,请检查安装路径。 - exit /b -) + echo 正在自动查找Python解释器... + where python >nul 2>&1 + if %errorlevel% equ 0 ( + for /f "delims=" %%i in ('where python') do ( + echo %%i | findstr /i /c:"!LocalAppData!\Microsoft\WindowsApps\python.exe" >nul + if errorlevel 1 ( + echo 找到Python解释器:%%i + set "py_path=%%i" + goto :validate_python + ) + ) + ) + set "search_paths=%ProgramFiles%\Git*;!LocalAppData!\Programs\Python\Python*" + for /d %%d in (!search_paths!) do ( + if exist "%%d\python.exe" ( + set "py_path=%%d\python.exe" + goto :validate_python + ) + ) + echo 没有找到Python解释器,要安装吗? + set /p pyinstall_confirm="继续?(Y/n): " + echo !pyinstall_confirm! + if /i "!pyinstall_confirm!"=="Y" ( + @REM echo 正在安装Python... + winget install --id Python.Python.3.13 -e --accept-package-agreements --accept-source-agreements + if %errorlevel% neq 0 ( + echo 安装失败,请手动安装Python + start https://www.python.org/downloads/ + exit /b + ) + echo 安装完成,正在验证Python... + goto search_python + + ) else ( + echo 取消安装Python,按任意键退出... + pause >nul + exit /b + ) + + echo 错误:未找到可用的Python解释器! + exit /b 1 + + :validate_python + "!py_path!" --version >nul 2>&1 + if %errorlevel% neq 0 ( + echo 无效的Python解释器:%py_path% + exit /b 1 + ) + + :: 提取安装目录 + for %%i in ("%py_path%") do set "PYTHON_HOME=%%~dpi" + set "PYTHON_HOME=%PYTHON_HOME:~0,-1%" +) +if not exist "%PYTHON_HOME%\python.exe" ( + echo Python路径验证失败:%PYTHON_HOME% + echo 请检查Python安装路径中是否有python.exe文件 + exit /b 1 +) +echo 成功设置Python路径:%PYTHON_HOME% + + + +:search_git if exist "%_root%\tools\git\bin" ( set "GIT_HOME=%_root%\tools\git\bin" -) else if git -v >nul 2>&1 ( - for /f "delims=" %%a in ('where git') do ( - set "GIT_HOME=%%~dpa" - ) ) else ( - echo Git环境未找到,请检查安装路径。 - exit /b + echo 正在自动查找Git... + + where git >nul 2>&1 + if %errorlevel% equ 0 ( + for /f "delims=" %%i in ('where git') do ( + set "git_path=%%i" + goto :validate_git + ) + ) + echo 正在扫描常见安装路径... + set "search_paths=!ProgramFiles!\Git\cmd" + for /d %%d in (!search_paths!) do ( + if exist "%%d\bin\git.exe" ( + set "git_path=%%d\bin\git.exe" + goto :validate_git + ) + ) + echo 没有找到Git,要安装吗? + set /p confirm="继续?(Y/N): " + if /i "!confirm!"=="Y" ( + echo 正在安装Git... + winget install --id Git.Git -e --accept-package-agreements --accept-source-agreements + if %errorlevel% neq 0 ( + echo 安装失败,请手动安装Git + start https://git-scm.com/download/win + exit /b + ) + echo 安装完成,正在验证Git... + where git >nul 2>&1 + if %errorlevel% equ 0 ( + for /f "delims=" %%i in ('where git') do ( + set "git_path=%%i" + goto :validate_git + ) + echo sba + goto :search_git + + ) else ( + echo 安装完成,但未找到Git,请手动安装Git + start https://git-scm.com/download/win + exit /b + ) + + ) else ( + echo 取消安装Git,按任意键退出... + pause >nul + exit /b + ) + + echo 错误:未找到可用的Git! + exit /b 1 + + :validate_git + "%git_path%" --version >nul 2>&1 + if %errorlevel% neq 0 ( + echo 无效的Git:%git_path% + exit /b 1 + ) + + :: 提取安装目录 + for %%i in ("%git_path%") do set "GIT_HOME=%%~dpi" + set "GIT_HOME=%GIT_HOME:~0,-1%" ) -set "GIT_HOME=%_root%\tools\git\bin" +@REM set "GIT_HOME=%_root%\tools\git\bin" set "PATH=%PYTHON_HOME%;%GIT_HOME%;%PATH%" +:install_maim +if not exist "%_root%\bot.py" ( + echo 你似乎没有安装麦麦Bot,要自动安装吗?(Y/N) + set /p confirm="继续?(Y/N): " + if /i "%confirm%"=="Y" ( + echo 要使用Git代理下载吗?(Y/N) + set /p proxy_confirm="继续?(Y/N): " + if /i "%proxy_confirm%"=="Y" ( + echo 正在安装麦麦Bot... + git clone https://ghfast.top/https://github.com/SengokuCola/MaiMBot . + ) else ( + echo 正在安装麦麦Bot... + git clone https://github.com/SengokuCola/MaiMBot . + ) + echo 安装完成,正在安装依赖... + python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple + python -m pip install -r requirements.txt + + echo 安装完成,要编辑配置文件吗?(Y/N) + set /p edit_confirm="继续?(Y/N): " + if /i "%edit_confirm%"=="Y" ( + goto config_menu + ) else ( + echo 取消编辑配置文件,按任意键返回主菜单... + ) +) + @REM git获取当前分支名并保存在变量里 for /f "delims=" %%b in ('git symbolic-ref --short HEAD 2^>nul') do ( @@ -56,10 +192,10 @@ for /f "delims=" %%b in ('git symbolic-ref --short HEAD 2^>nul') do ( echo 分支名: %BRANCH% if "%BRANCH%"=="main" ( set "BRANCH_COLOR=" -) else if "%BRANCH%"=="debug" ( +) else if "%BRANCH%"=="main-fix" ( set "BRANCH_COLOR=" -) else if "%BRANCH%"=="stable-dev" ( - set "BRANCH_COLOR=" +@REM ) else if "%BRANCH%"=="stable-dev" ( +@REM set "BRANCH_COLOR=" ) else ( set "BRANCH_COLOR=" ) @@ -68,14 +204,14 @@ if "%BRANCH%"=="main" ( :menu -@chcp 65001 +@chcp 936 cls echo 麦麦Bot控制台 v%VERSION% 当前分支: %BRANCH_COLOR%%BRANCH% echo ====================== echo 1. 更新并启动麦麦Bot (默认) echo 2. 直接启动麦麦Bot -echo 3. 麦麦配置菜单 -echo 4. 麦麦神奇工具箱 +echo 3. 启动麦麦配置界面 +echo 4. 打开麦麦神奇工具箱 echo 5. 退出 echo ====================== @@ -94,38 +230,31 @@ timeout /t 2 >nul goto menu :config_menu -@chcp 65001 +@chcp 936 cls -echo 配置菜单 -echo ====================== -echo 1. 编辑配置文件 (config.toml) -echo 2. 编辑环境变量 (.env.prod) -echo 3. 打开安装目录 -echo 4. 返回主菜单 -echo ====================== +if not exist config/bot_config.toml ( + copy template/bot_config_template.toml config/bot_config.toml +) +if not exist .env.prod ( + copy template.env .env.prod +) -set /p choice="请输入选项数字: " +python webui.py -if "%choice%"=="1" goto edit_config -if "%choice%"=="2" goto edit_env -if "%choice%"=="3" goto open_dir -if "%choice%"=="4" goto menu - -echo 无效的输入,请输入1-4之间的数字 -timeout /t 2 >nul -goto config_menu +goto menu :tools_menu -@chcp 65001 +@chcp 936 cls echo 麦麦时尚工具箱 当前分支: %BRANCH_COLOR%%BRANCH% echo ====================== echo 1. 更新依赖 echo 2. 切换分支 -echo 3. 更新配置文件 -echo 4. 学习新的知识库 -echo 5. 打开知识库文件夹 -echo 6. 返回主菜单 +echo 3. 重置当前分支 +echo 4. 更新配置文件 +echo 5. 学习新的知识库 +echo 6. 打开知识库文件夹 +echo 7. 返回主菜单 echo ====================== set /p choice="请输入选项数字: " @@ -135,6 +264,7 @@ if "%choice%"=="3" goto update_config if "%choice%"=="4" goto learn_new_knowledge if "%choice%"=="5" goto open_knowledge_folder if "%choice%"=="6" goto menu +if "%choice%"=="3" goto open_dir echo 无效的输入,请输入1-6之间的数字 timeout /t 2 >nul @@ -154,16 +284,24 @@ goto tools_menu cls echo 正在切换分支... echo 当前分支: %BRANCH% -echo 可用分支: main, debug, stable-dev -echo 请输入要切换到的分支名 (main/debug/stable-dev): +@REM echo 可用分支: main, debug, stable-dev +echo 1. 切换到main +echo 2. 切换到main-fix +echo 请输入要切换到的分支: set /p branch_name="分支名: " if "%branch_name%"=="" set branch_name=main if "%branch_name%"=="main" ( set "BRANCH_COLOR=" -) else if "%branch_name%"=="debug" ( +) else if "%branch_name%"=="main-fix" ( set "BRANCH_COLOR=" -) else if "%branch_name%"=="stable-dev" ( - set "BRANCH_COLOR=" +@REM ) else if "%branch_name%"=="stable-dev" ( +@REM set "BRANCH_COLOR=" +) else if "%branch_name%"=="1" ( + set "BRANCH_COLOR=" + set "branch_name=main" +) else if "%branch_name%"=="2" ( + set "BRANCH_COLOR=" + set "branch_name=main-fix" ) else ( echo 无效的分支名, 请重新输入 timeout /t 2 >nul @@ -280,23 +418,6 @@ echo Bot已停止运行,按任意键返回主菜单... pause >nul goto menu -:edit_config -if exist config/bot_config.toml ( - start notepad config/bot_config.toml -) else ( - echo 配置文件 bot_config.toml 不存在! - timeout /t 2 >nul -) -goto menu - -:edit_env -if exist .env.prod ( - start notepad .env.prod -) else ( - echo 环境文件 .env.prod 不存在! - timeout /t 2 >nul -) -goto menu :open_dir start explorer "%cd%" From f0b338b4ca6c59bb055379bda2a5d502fe3cc6f8 Mon Sep 17 00:00:00 2001 From: KawaiiYusora Date: Sat, 15 Mar 2025 18:53:46 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20feat(MaiLauncher.bat):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=84=9A=E6=9C=AC=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0MongoDB=E6=94=AF=E6=8C=81=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E8=BF=9BGit=E5=AE=89=E8=A3=85=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MaiLauncher.bat | 149 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 101 insertions(+), 48 deletions(-) diff --git a/MaiLauncher.bat b/MaiLauncher.bat index 9d2b5965e..32adef2d7 100644 --- a/MaiLauncher.bat +++ b/MaiLauncher.bat @@ -1,5 +1,5 @@ @echo off -setlocal enabledelayedexpansion +@setlocal enabledelayedexpansion @chcp 936 @REM 设置版本号 @@ -11,9 +11,10 @@ title 麦麦Bot控制台 v%VERSION% set "_root=%~dp0" set "_root=%_root:~0,-1%" cd "%_root%" -echo "%_root% + :search_python +cls if exist "%_root%\python" ( set "PYTHON_HOME=%_root%\python" ) else if exist "%_root%\venv" ( @@ -42,9 +43,9 @@ if exist "%_root%\python" ( ) echo 没有找到Python解释器,要安装吗? set /p pyinstall_confirm="继续?(Y/n): " - echo !pyinstall_confirm! if /i "!pyinstall_confirm!"=="Y" ( - @REM echo 正在安装Python... + cls + echo 正在安装Python... winget install --id Python.Python.3.13 -e --accept-package-agreements --accept-source-agreements if %errorlevel% neq 0 ( echo 安装失败,请手动安装Python @@ -84,6 +85,7 @@ echo 成功设置Python路径:%PYTHON_HOME% :search_git +cls if exist "%_root%\tools\git\bin" ( set "GIT_HOME=%_root%\tools\git\bin" ) else ( @@ -98,22 +100,36 @@ if exist "%_root%\tools\git\bin" ( ) echo 正在扫描常见安装路径... set "search_paths=!ProgramFiles!\Git\cmd" - for /d %%d in (!search_paths!) do ( - if exist "%%d\bin\git.exe" ( - set "git_path=%%d\bin\git.exe" + for /f "tokens=*" %%d in ("!search_paths!") do ( + if exist "%%d\git.exe" ( + set "git_path=%%d\git.exe" goto :validate_git ) ) echo 没有找到Git,要安装吗? set /p confirm="继续?(Y/N): " if /i "!confirm!"=="Y" ( + cls echo 正在安装Git... - winget install --id Git.Git -e --accept-package-agreements --accept-source-agreements - if %errorlevel% neq 0 ( - echo 安装失败,请手动安装Git + set "custom_url=https://ghfast.top/https://github.com/git-for-windows/git/releases/download/v2.48.1.windows.1/Git-2.48.1-64-bit.exe" + + set "download_path=%TEMP%\Git-Installer.exe" + + echo 正在下载Git安装包... + curl -L -o "!download_path!" "!custom_url!" + + if exist "!download_path!" ( + echo 下载成功,开始安装Git... + start /wait "" "!download_path!" /SILENT /NORESTART + ) else ( + echo 下载失败,请手动安装Git start https://git-scm.com/download/win exit /b ) + + del "!download_path!" + echo 临时文件已清理。 + echo 安装完成,正在验证Git... where git >nul 2>&1 if %errorlevel% equ 0 ( @@ -121,7 +137,6 @@ if exist "%_root%\tools\git\bin" ( set "git_path=%%i" goto :validate_git ) - echo sba goto :search_git ) else ( @@ -151,35 +166,72 @@ if exist "%_root%\tools\git\bin" ( set "GIT_HOME=%GIT_HOME:~0,-1%" ) +:search_mongodb +cls +sc query | findstr /i "MongoDB" >nul +if %errorlevel% neq 0 ( + echo MongoDB服务未运行,正在尝试启动... + net start MongoDB >nul 2>&1 + if %errorlevel% neq 0 ( + echo MongoDB服务启动失败,可能是没有安装,要安装吗? + set /p confirm="继续?(Y/N): " + if /i "!confirm!"=="Y" ( + echo 正在安装MongoDB... + winget install --id MongoDB.Server -e --accept-package-agreements --accept-source-agreements + echo 安装完成,正在启动MongoDB服务... + net start MongoDB + if %errorlevel% neq 0 ( + echo 启动MongoDB服务失败,请手动启动 + exit /b + ) + echo MongoDB服务已启动 + ) else ( + echo 取消安装MongoDB,按任意键退出... + pause >nul + exit /b + ) + ) +) else ( + echo MongoDB服务已运行 +) @REM set "GIT_HOME=%_root%\tools\git\bin" set "PATH=%PYTHON_HOME%;%GIT_HOME%;%PATH%" :install_maim -if not exist "%_root%\bot.py" ( - echo 你似乎没有安装麦麦Bot,要自动安装吗?(Y/N) +if not exist "!_root!\bot.py" ( + cls + echo 你似乎没有安装麦麦Bot,要安装在当前目录吗? set /p confirm="继续?(Y/N): " - if /i "%confirm%"=="Y" ( - echo 要使用Git代理下载吗?(Y/N) + if /i "!confirm!"=="Y" ( + echo 要使用Git代理下载吗? set /p proxy_confirm="继续?(Y/N): " - if /i "%proxy_confirm%"=="Y" ( + if /i "!proxy_confirm!"=="Y" ( echo 正在安装麦麦Bot... - git clone https://ghfast.top/https://github.com/SengokuCola/MaiMBot . + git clone https://ghfast.top/https://github.com/SengokuCola/MaiMBot ) else ( echo 正在安装麦麦Bot... - git clone https://github.com/SengokuCola/MaiMBot . + git clone https://github.com/SengokuCola/MaiMBot ) + xcopy /E /H /I MaiMBot . >nul 2>&1 + rmdir /s /q MaiMBot + git checkout main-fix + echo 安装完成,正在安装依赖... python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple + python -m pip install virtualenv + python -m virtualenv venv + call venv\Scripts\activate.bat python -m pip install -r requirements.txt - echo 安装完成,要编辑配置文件吗?(Y/N) + echo 安装完成,要编辑配置文件吗? set /p edit_confirm="继续?(Y/N): " - if /i "%edit_confirm%"=="Y" ( + if /i "!edit_confirm!"=="Y" ( goto config_menu ) else ( echo 取消编辑配置文件,按任意键返回主菜单... ) + ) ) @@ -190,9 +242,9 @@ for /f "delims=" %%b in ('git symbolic-ref --short HEAD 2^>nul') do ( @REM 根据不同分支名给分支名字符串使用不同颜色 echo 分支名: %BRANCH% -if "%BRANCH%"=="main" ( +if "!BRANCH!"=="main" ( set "BRANCH_COLOR=" -) else if "%BRANCH%"=="main-fix" ( +) else if "!BRANCH!"=="main-fix" ( set "BRANCH_COLOR=" @REM ) else if "%BRANCH%"=="stable-dev" ( @REM set "BRANCH_COLOR=" @@ -217,13 +269,13 @@ echo ====================== set /p choice="请输入选项数字 (1-5)并按下回车以选择: " -if "%choice%"=="" set choice=1 +if "!choice!"=="" set choice=1 -if "%choice%"=="1" goto update_and_start -if "%choice%"=="2" goto start_bot -if "%choice%"=="3" goto config_menu -if "%choice%"=="4" goto tools_menu -if "%choice%"=="5" exit /b +if "!choice!"=="1" goto update_and_start +if "!choice!"=="2" goto start_bot +if "!choice!"=="3" goto config_menu +if "!choice!"=="4" goto tools_menu +if "!choice!"=="5" exit /b echo 无效的输入,请输入1-5之间的数字 timeout /t 2 >nul @@ -233,13 +285,15 @@ goto menu @chcp 936 cls if not exist config/bot_config.toml ( - copy template/bot_config_template.toml config/bot_config.toml + copy /Y "template\bot_config_template.toml" "config\bot_config.toml" + re + ) if not exist .env.prod ( - copy template.env .env.prod + copy /Y "template\.env.prod" ".env.prod" ) -python webui.py +start python webui.py goto menu @@ -258,13 +312,12 @@ echo 7. 返回主菜单 echo ====================== set /p choice="请输入选项数字: " -if "%choice%"=="1" goto update_dependencies -if "%choice%"=="2" goto switch_branch -if "%choice%"=="3" goto update_config -if "%choice%"=="4" goto learn_new_knowledge -if "%choice%"=="5" goto open_knowledge_folder -if "%choice%"=="6" goto menu -if "%choice%"=="3" goto open_dir +if "!choice!"=="1" goto update_dependencies +if "!choice!"=="2" goto switch_branch +if "!choice!"=="3" goto update_config +if "!choice!"=="4" goto learn_new_knowledge +if "!choice!"=="5" goto open_knowledge_folder +if "!choice!"=="6" goto menu echo 无效的输入,请输入1-6之间的数字 timeout /t 2 >nul @@ -325,7 +378,7 @@ echo 继续请按Y,取消请按任意键... set /p confirm="继续?(Y/N): " if /i "%confirm%"=="Y" ( echo 正在更新配置文件... - python\python.exe config\auto_update.py + python.exe config\auto_update.py echo 配置文件更新完成,按任意键返回工具箱菜单... ) else ( echo 取消更新配置文件,按任意键返回工具箱菜单... @@ -341,7 +394,7 @@ echo 继续请按Y,取消请按任意键... set /p confirm="继续?(Y/N): " if /i "%confirm%"=="Y" ( echo 正在学习新的知识库... - python\python.exe src\plugins\zhishi\knowledge_library.py + python.exe src\plugins\zhishi\knowledge_library.py echo 学习完成,按任意键返回工具箱菜单... ) else ( echo 取消学习新的知识库,按任意键返回工具箱菜单... @@ -366,19 +419,19 @@ goto tools_menu :update_and_start cls :retry_git_pull -tools\git\bin\git.exe pull > temp.log 2>&1 +git pull > temp.log 2>&1 findstr /C:"detected dubious ownership" temp.log >nul if %errorlevel% equ 0 ( echo 检测到仓库权限问题,正在自动修复... - tools\git\bin\git.exe config --global --add safe.directory "%cd%" + git config --global --add safe.directory "%cd%" echo 已添加例外,正在重试git pull... del temp.log goto retry_git_pull ) del temp.log echo 正在更新依赖... -python\python.exe -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple -python\python.exe -m pip install -r requirements.txt && cls +python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple +python -m pip install -r requirements.txt && cls echo 当前代理设置: echo HTTP_PROXY=%HTTP_PROXY% @@ -390,7 +443,7 @@ set HTTPS_PROXY= set no_proxy=0.0.0.0/32 REM chcp 65001 -python\python.exe bot.py +python bot.py echo. echo Bot已停止运行,按任意键返回主菜单... pause >nul @@ -399,8 +452,8 @@ goto menu :start_bot cls echo 正在更新依赖... -python\python.exe -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple -python\python.exe -m pip install -r requirements.txt && cls +python -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple +python -m pip install -r requirements.txt && cls echo 当前代理设置: echo HTTP_PROXY=%HTTP_PROXY% @@ -412,7 +465,7 @@ set HTTPS_PROXY= set no_proxy=0.0.0.0/32 REM chcp 65001 -python\python.exe bot.py +python bot.py echo. echo Bot已停止运行,按任意键返回主菜单... pause >nul From c7aeb022577b69b42f51428b62a89a1f141e7c0b Mon Sep 17 00:00:00 2001 From: KawaiiYusora Date: Sat, 15 Mar 2025 18:56:13 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=90=9B=20fix(MaiLauncher.bat):=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=A4=9A=E4=BD=99=E7=9A=84=20`re`=20?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MaiLauncher.bat | 1 - 1 file changed, 1 deletion(-) diff --git a/MaiLauncher.bat b/MaiLauncher.bat index 32adef2d7..3e61ae3af 100644 --- a/MaiLauncher.bat +++ b/MaiLauncher.bat @@ -286,7 +286,6 @@ goto menu cls if not exist config/bot_config.toml ( copy /Y "template\bot_config_template.toml" "config\bot_config.toml" - re ) if not exist .env.prod ( From 980aab3ecd1c1fd300924a9c5d70fea81507ed3f Mon Sep 17 00:00:00 2001 From: KawaiiYusora Date: Sat, 15 Mar 2025 20:45:28 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=A8=20feat(MaiLauncher.bat):=20Bump?= =?UTF-8?q?=20the=20Launcher=20version=20to=201.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MaiLauncher.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MaiLauncher.bat b/MaiLauncher.bat index 3e61ae3af..5613f05c2 100644 --- a/MaiLauncher.bat +++ b/MaiLauncher.bat @@ -3,7 +3,7 @@ @chcp 936 @REM 设置版本号 -set "VERSION=0.3" +set "VERSION=1.0" title 麦麦Bot控制台 v%VERSION%