mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2025-07-27 16:51:17 +00:00
🐛 fix 通道无法在进程内传递消息的问题
This commit is contained in:
21
liteyuki/plugins/code_watchdog/__init__.py
Normal file
21
liteyuki/plugins/code_watchdog/__init__.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
|
||||
@Time : 2024/8/11 下午8:50
|
||||
@Author : snowykami
|
||||
@Email : snowykami@outlook.com
|
||||
@File : __init__.py.py
|
||||
@Software: PyCharm
|
||||
"""
|
||||
from liteyuki.core import IS_MAIN_PROCESS
|
||||
from liteyuki.plugin import PluginMetadata
|
||||
|
||||
from .observer import *
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="代码热重载监视",
|
||||
)
|
||||
|
||||
if IS_MAIN_PROCESS:
|
||||
config = get_config("liteyuki.reload")
|
44
liteyuki/plugins/code_watchdog/observer.py
Normal file
44
liteyuki/plugins/code_watchdog/observer.py
Normal file
@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
|
||||
@Time : 2024/8/11 下午10:01
|
||||
@Author : snowykami
|
||||
@Email : snowykami@outlook.com
|
||||
@File : observer.py
|
||||
@Software: PyCharm
|
||||
"""
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from watchdog.observers import Observer
|
||||
from liteyuki import get_config, logger, get_bot
|
||||
|
||||
liteyuki_bot = get_bot()
|
||||
|
||||
if get_config("debug", False):
|
||||
|
||||
src_directories = (
|
||||
"src/nonebot_plugins",
|
||||
"src/utils",
|
||||
)
|
||||
src_excludes_extensions = (
|
||||
"pyc",
|
||||
)
|
||||
logger.debug("Liteyuki Reload enabled, watching for file changes...")
|
||||
|
||||
class CodeModifiedHandler(FileSystemEventHandler):
|
||||
"""
|
||||
Handler for code file changes
|
||||
"""
|
||||
def on_modified(self, event):
|
||||
if event.src_path.endswith(
|
||||
src_excludes_extensions) or event.is_directory or "__pycache__" in event.src_path:
|
||||
return
|
||||
logger.info(f"{event.src_path} modified, reloading bot...")
|
||||
liteyuki_bot.restart_process("nonebot")
|
||||
|
||||
code_modified_handler = CodeModifiedHandler()
|
||||
|
||||
observer = Observer()
|
||||
for directory in src_directories:
|
||||
observer.schedule(code_modified_handler, directory, recursive=True)
|
||||
observer.start()
|
Reference in New Issue
Block a user