From 9cb6104a294ea41f332f5fb9b9afc156de555bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=95=80=E9=93=AC=E9=85=B8=E9=92=BE?= <148796996+K2cr2O1@users.noreply.github.com> Date: Thu, 5 Mar 2026 22:58:53 +0800 Subject: [PATCH] Create add_plugins.py --- scripts/add_plugins.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 scripts/add_plugins.py diff --git a/scripts/add_plugins.py b/scripts/add_plugins.py new file mode 100644 index 0000000..5e99f1d --- /dev/null +++ b/scripts/add_plugins.py @@ -0,0 +1,41 @@ +import os +import sys + +def create_plugin(plugin_name): + base = os.path.dirname(__file__) + plugin_dir = os.path.join(base, "../plugins") + os.makedirs(plugin_dir, exist_ok=True) + + file_name = f"{plugin_name.lower()}.py" + file_path = os.path.join(plugin_dir, file_name) + + if os.path.exists(file_path): + print(f"插件已存在") + return + + template = f'''from core.managers.command_manager import matcher +from core.bot import Bot +from models.events.message import MessageEvent +from core.permission import Permission + +__plugin_meta__ = {{ + "name": "{plugin_name.lower()}", + "description": "", + "usage": "" +}} + +@matcher.command("{plugin_name.lower()}") +async def _(bot: Bot, event: MessageEvent): + pass +''' + + with open(file_path, "w", encoding="utf-8") as f: + f.write(template) + + print(f"插件创建成功:{file_path}") + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("用法:python create_plugin.py 插件名") + sys.exit(1) + create_plugin(sys.argv[1])