From 9b5be6f56e7448f2e0449f1c29d2216a1ccac47b Mon Sep 17 00:00:00 2001 From: K2cr2O1 <2221577113@qq.com> Date: Thu, 1 Jan 2026 20:20:42 +0800 Subject: [PATCH] =?UTF-8?q?Gemini=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base_plugins/__init__.py | 10 +++++++++- base_plugins/echo.py | 4 ++-- main.py | 18 +++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/base_plugins/__init__.py b/base_plugins/__init__.py index c0098c3..dda9920 100644 --- a/base_plugins/__init__.py +++ b/base_plugins/__init__.py @@ -5,7 +5,15 @@ import sys def load_all_plugins(): - """扫描并加载当前包下所有的插件(支持文件和文件夹)""" + """ + 扫描并加载当前包下所有的插件(支持文件和文件夹) + + 该函数会遍历当前目录下的所有模块: + 1. 如果模块已加载,则执行 reload 操作(用于热重载) + 2. 如果模块未加载,则执行 import 操作 + + 加载过程中会打印详细的日志信息。 + """ package_name = __package__ package_path = [os.path.dirname(__file__)] diff --git a/base_plugins/echo.py b/base_plugins/echo.py index a91551d..b511690 100644 --- a/base_plugins/echo.py +++ b/base_plugins/echo.py @@ -27,11 +27,11 @@ async def handle_echo(bot: Bot, event: MessageEvent, args: list[str]): @matcher.command("poke") async def handle_poke(bot: Bot, event: MessageEvent, args: list[str]): """ - 处理 echo 指令,原样回复用户输入的内容 + 处理 poke 指令,发送群戳一戳 :param bot: Bot 实例 :param event: 消息事件对象 - :param args: 指令参数列表 + :param args: 指令参数列表(本指令不使用参数) """ await bot.call_api("group_poke", { diff --git a/main.py b/main.py index 0e12c54..f96eec0 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,7 @@ """ NEO Bot 主程序入口 + +负责启动 WebSocket 连接,初始化插件系统,并提供热重载功能。 """ import asyncio import os @@ -15,14 +17,24 @@ from core import WS class PluginReloadHandler(FileSystemEventHandler): """ 文件变更处理器,用于热重载插件 + + 继承自 watchdog.events.FileSystemEventHandler, + 监听 base_plugins 目录下的文件变化,并触发插件重载。 """ def __init__(self): + """ + 初始化处理器 + + 设置冷却时间,防止短时间内多次触发重载。 + """ self.last_reload_time = 0 self.cooldown = 1.0 # 冷却时间,防止短时间内多次重载 def on_any_event(self, event): """ 处理所有文件事件 + + :param event: watchdog 事件对象 """ if event.is_directory: return @@ -55,7 +67,11 @@ class PluginReloadHandler(FileSystemEventHandler): async def main(): """ - 主函数,启动 WebSocket 连接 + 主函数 + + 1. 启动文件监控(热重载) + 2. 初始化 WebSocket 客户端 + 3. 建立连接并保持运行 """ # 启动文件监控 # 监控 base_plugins 目录