Gemini添加更多注释
This commit is contained in:
@@ -5,7 +5,15 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
def load_all_plugins():
|
def load_all_plugins():
|
||||||
"""扫描并加载当前包下所有的插件(支持文件和文件夹)"""
|
"""
|
||||||
|
扫描并加载当前包下所有的插件(支持文件和文件夹)
|
||||||
|
|
||||||
|
该函数会遍历当前目录下的所有模块:
|
||||||
|
1. 如果模块已加载,则执行 reload 操作(用于热重载)
|
||||||
|
2. 如果模块未加载,则执行 import 操作
|
||||||
|
|
||||||
|
加载过程中会打印详细的日志信息。
|
||||||
|
"""
|
||||||
package_name = __package__
|
package_name = __package__
|
||||||
package_path = [os.path.dirname(__file__)]
|
package_path = [os.path.dirname(__file__)]
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ async def handle_echo(bot: Bot, event: MessageEvent, args: list[str]):
|
|||||||
@matcher.command("poke")
|
@matcher.command("poke")
|
||||||
async def handle_poke(bot: Bot, event: MessageEvent, args: list[str]):
|
async def handle_poke(bot: Bot, event: MessageEvent, args: list[str]):
|
||||||
"""
|
"""
|
||||||
处理 echo 指令,原样回复用户输入的内容
|
处理 poke 指令,发送群戳一戳
|
||||||
|
|
||||||
:param bot: Bot 实例
|
:param bot: Bot 实例
|
||||||
:param event: 消息事件对象
|
:param event: 消息事件对象
|
||||||
:param args: 指令参数列表
|
:param args: 指令参数列表(本指令不使用参数)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
await bot.call_api("group_poke", {
|
await bot.call_api("group_poke", {
|
||||||
|
|||||||
18
main.py
18
main.py
@@ -1,5 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
NEO Bot 主程序入口
|
NEO Bot 主程序入口
|
||||||
|
|
||||||
|
负责启动 WebSocket 连接,初始化插件系统,并提供热重载功能。
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
@@ -15,14 +17,24 @@ from core import WS
|
|||||||
class PluginReloadHandler(FileSystemEventHandler):
|
class PluginReloadHandler(FileSystemEventHandler):
|
||||||
"""
|
"""
|
||||||
文件变更处理器,用于热重载插件
|
文件变更处理器,用于热重载插件
|
||||||
|
|
||||||
|
继承自 watchdog.events.FileSystemEventHandler,
|
||||||
|
监听 base_plugins 目录下的文件变化,并触发插件重载。
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
初始化处理器
|
||||||
|
|
||||||
|
设置冷却时间,防止短时间内多次触发重载。
|
||||||
|
"""
|
||||||
self.last_reload_time = 0
|
self.last_reload_time = 0
|
||||||
self.cooldown = 1.0 # 冷却时间,防止短时间内多次重载
|
self.cooldown = 1.0 # 冷却时间,防止短时间内多次重载
|
||||||
|
|
||||||
def on_any_event(self, event):
|
def on_any_event(self, event):
|
||||||
"""
|
"""
|
||||||
处理所有文件事件
|
处理所有文件事件
|
||||||
|
|
||||||
|
:param event: watchdog 事件对象
|
||||||
"""
|
"""
|
||||||
if event.is_directory:
|
if event.is_directory:
|
||||||
return
|
return
|
||||||
@@ -55,7 +67,11 @@ class PluginReloadHandler(FileSystemEventHandler):
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""
|
"""
|
||||||
主函数,启动 WebSocket 连接
|
主函数
|
||||||
|
|
||||||
|
1. 启动文件监控(热重载)
|
||||||
|
2. 初始化 WebSocket 客户端
|
||||||
|
3. 建立连接并保持运行
|
||||||
"""
|
"""
|
||||||
# 启动文件监控
|
# 启动文件监控
|
||||||
# 监控 base_plugins 目录
|
# 监控 base_plugins 目录
|
||||||
|
|||||||
Reference in New Issue
Block a user