-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
NoneBot 开发环境重载监视器 | ||
""" | ||
import os.path | ||
|
||
from liteyuki.dev import observer | ||
from liteyuki import get_bot, logger | ||
from liteyuki.utils import IS_MAIN_PROCESS | ||
from watchdog.events import FileSystemEvent | ||
|
||
|
||
bot = 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...") | ||
bot.restart_process("nonebot") |