1
0
forked from bot/app

新增observer类和开发调试器

This commit is contained in:
2024-08-12 04:45:59 +08:00
parent 83325e63ea
commit c9157f0e2c
20 changed files with 222 additions and 214 deletions

View File

@ -15,14 +15,13 @@ from liteyuki.plugin import PluginMetadata
from liteyuki import get_bot
from liteyuki.comm import Channel, set_channel
from liteyuki.core import IS_MAIN_PROCESS
from .nb_utils import adapter_manager, driver_manager
__plugin_meta__ = PluginMetadata(
name="NoneBot2启动器",
)
liteyuki = get_bot()
def nb_run(chan_active: "Channel", chan_passive: "Channel", **kwargs):
"""
@ -39,7 +38,7 @@ def nb_run(chan_active: "Channel", chan_passive: "Channel", **kwargs):
set_channel("nonebot-active", chan_active)
set_channel("nonebot-passive", chan_passive)
kwargs.update(kwargs.get("nonebot", {})) # nonebot配置优先
kwargs.update(kwargs.get("nonebot", {})) # nonebot配置优先
nonebot.init(**kwargs)
driver_manager.init(config=kwargs)
@ -50,6 +49,11 @@ def nb_run(chan_active: "Channel", chan_passive: "Channel", **kwargs):
if IS_MAIN_PROCESS:
from .dev_reloader import *
liteyuki = get_bot()
@liteyuki.on_after_start
def start_run_nonebot():
liteyuki.process_manager.add_target(name="nonebot", target=nb_run, args=(), kwargs=liteyuki.config)

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
"""
NoneBot 开发环境重载监视器
"""
import os.path
from liteyuki.dev import observer
from liteyuki import get_bot, logger
from watchdog.events import FileSystemEvent
liteyuki = get_bot()
exclude_extensions = (".pyc", ".pyo")
@observer.on_file_system_event(
directories=("src/nonebot_plugins",),
event_filter=lambda event: not event.src_path.endswith(exclude_extensions) and ("__pycache__" not in event.src_path ) and os.path.isfile(event.src_path)
)
def restart_nonebot_process(event: FileSystemEvent):
logger.debug(f"File {event.src_path} changed, reloading nonebot...")
liteyuki.restart_process("nonebot")