🐛 修复更新会消除插件的问题

This commit is contained in:
CMHopeSunshine 2023-01-07 13:30:16 +08:00
parent 190a9b5ae1
commit 7d08988347
2 changed files with 19 additions and 16 deletions

View File

@ -4,7 +4,7 @@ from nonebot import get_driver
from .logger import logger
from .scheduler import scheduler
__version__ = '3.0.1'
__version__ = '3.0.2'
DRIVER = get_driver()
try:

View File

@ -39,28 +39,31 @@ async def check_update():
@run_sync
def update():
pyproject_file = Path().parent / 'pyproject.toml'
pyproject_raw_content = pyproject_file.read_text(encoding='utf-8')
if raw_plugins_load := re.search(r'^plugins = \[.*]$', pyproject_raw_content, flags=re.M):
pyproject_new_content = pyproject_raw_content.replace(raw_plugins_load.group(), 'plugins = []')
else:
pyproject_new_content = pyproject_raw_content
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
try:
repo = git.Repo(Path().absolute())
except InvalidGitRepositoryError:
return '没有发现git仓库无法通过git更新请手动下载最新版本的文件进行替换。'
origin = repo.remotes.origin
pyproject_file = Path().parent / 'pyproject.toml'
pyproject_raw_content = pyproject_file.read_text(encoding='utf-8')
if raw_plugins_load := re.search(r'^plugins = \[.+]$', pyproject_raw_content, flags=re.M):
pyproject_new_content = pyproject_raw_content.replace(raw_plugins_load.group(), 'plugins = []')
else:
pyproject_new_content = pyproject_raw_content
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
try:
origin.pull()
msg = f'更新完成,版本:{__version__}\n最新更新日志为:\n{repo.head.commit.message.replace(":bug:", "🐛").replace(":sparkles:", "").replace(":memo:", "📝")}\n可使用命令[@bot 重启]重启{NICKNAME}'
except GitCommandError as e:
if 'timeout' in e or 'unable to access' in e:
return '更新失败连接git仓库超时请重试或修改源为代理源后再重试。'
msg = '更新失败连接git仓库超时请重试或修改源为代理源后再重试。'
elif ' Your local changes to the following files would be overwritten by merge' in e:
return ('error: Your local changes to the following files would be overwritten by merge\n'
'更新失败本地修改过文件导致冲突可在命令行运行git pull查看冲突的文件是哪些请解决冲突后再更新。')
return f'更新失败,错误信息:{e},请尝试手动进行更新'
pyproject_new_content = pyproject_file.read_text(encoding='utf-8')
pyproject_new_content = pyproject_new_content.replace('plugins = []', raw_plugins_load.group())
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
return f'更新完成,版本:{__version__}\n最新更新日志为:\n{repo.head.commit.message.replace(":bug:", "🐛").replace(":sparkles:", "").replace(":memo:", "📝")}\n可使用命令[@bot 重启]重启{NICKNAME}'
msg = ('error: Your local changes to the following files would be overwritten by merge\n'
'更新失败本地修改过文件导致冲突可在命令行运行git pull查看冲突的文件是哪些请解决冲突后再更新。')
else:
msg = f'更新失败,错误信息:{e},请尝试手动进行更新'
if raw_plugins_load:
pyproject_new_content = pyproject_file.read_text(encoding='utf-8')
pyproject_new_content = pyproject_new_content.replace('plugins = []', raw_plugins_load.group())
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
return msg