🐛 修复安装了某些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 os
import asyncio import asyncio
import contextlib
import random import random
import sys import sys
from pathlib import Path from pathlib import Path
@ -138,10 +139,14 @@ async def _(bot: Bot, event: MessageEvent):
) )
await asyncio.sleep(0.25) await asyncio.sleep(0.25)
save_json(reboot_data, Path() / 'rebooting.json') save_json(reboot_data, Path() / 'rebooting.json')
await get_app().router.shutdown() with contextlib.suppress(Exception):
if sys.argv[0].endswith('nb'): await get_app().router.shutdown()
sys.argv[0] = 'bot.py' reboot_arg = (
os.execv(sys.executable, [sys.executable] + sys.argv) [sys.executable] + sys.argv
if sys.argv[0].endswith('.py')
else [sys.executable, 'bot.py']
)
os.execv(sys.executable, reboot_arg)
@run_cmd.handle() @run_cmd.handle()

View File

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