🐛 修复安装了某些nb插件时重启命令报错问题#390

This commit is contained in:
CMHopeSunshine 2023-02-14 23:06:03 +08:00
parent 437048cfed
commit c59b0fad67
2 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,6 @@
import os
import asyncio
import contextlib
import random
import sys
from pathlib import Path
@ -138,10 +139,14 @@ async def _(bot: Bot, event: MessageEvent):
)
await asyncio.sleep(0.25)
save_json(reboot_data, Path() / 'rebooting.json')
await get_app().router.shutdown()
if sys.argv[0].endswith('nb'):
sys.argv[0] = 'bot.py'
os.execv(sys.executable, [sys.executable] + sys.argv)
with contextlib.suppress(Exception):
await get_app().router.shutdown()
reboot_arg = (
[sys.executable] + sys.argv
if sys.argv[0].endswith('.py')
else [sys.executable, 'bot.py']
)
os.execv(sys.executable, reboot_arg)
@run_cmd.handle()

View File

@ -1,4 +1,5 @@
import asyncio
import contextlib
import datetime
import os
import sys
@ -136,7 +137,11 @@ async def bot_restart():
{'session_type': 'private', 'session_id': SUPERUSERS[0]},
Path() / 'rebooting.json',
)
await get_app().router.shutdown()
if sys.argv[0].endswith('nb'):
sys.argv[0] = 'bot.py'
os.execv(sys.executable, [sys.executable] + sys.argv)
with contextlib.suppress(Exception):
await get_app().router.shutdown()
reboot_arg = (
[sys.executable] + sys.argv
if sys.argv[0].endswith('.py')
else [sys.executable, 'bot.py']
)
os.execv(sys.executable, reboot_arg)