From 7adf404600f73a864120b628932cb1168d304217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Tue, 9 Aug 2022 20:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20=E7=A7=BB=E5=8A=A8=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=20=E5=8C=BA=E5=88=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=8F=92=E4=BB=B6=E5=92=8C=E6=9F=A5=E8=AF=A2=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/{ => genshin}/abyss.py | 0 plugins/{ => genshin}/adduser.py | 0 plugins/{ => genshin}/artifact_rate.py | 0 plugins/{ => genshin}/daily_note.py | 0 plugins/{ => genshin}/gacha/__init__.py | 0 plugins/{ => genshin}/gacha/gacha.py | 2 +- plugins/{ => genshin}/gacha/wish.py | 0 plugins/{ => genshin}/help.py | 0 plugins/{ => genshin}/ledger.py | 0 plugins/{ => genshin}/map/__init__.py | 0 plugins/{ => genshin}/map/map.py | 0 plugins/{ => genshin}/map/model.py | 0 plugins/{ => genshin}/post.py | 0 plugins/{ => genshin}/sign.py | 0 plugins/{ => genshin}/strategy.py | 0 plugins/{ => genshin}/uid.py | 0 plugins/{ => genshin}/weapon.py | 0 plugins/{ => genshin}/wiki.py | 0 plugins/{ => system}/admin.py | 0 plugins/{ => system}/errorhandler.py | 0 plugins/{ => system}/inline.py | 0 plugins/{ => system}/start.py | 0 utils/plugins/manager.py | 1 - utils/plugins/register.py | 13 ++++++----- utils/service/inject.py | 4 ++-- utils/service/manager.py | 30 ++++++++++++------------- 26 files changed, 26 insertions(+), 24 deletions(-) rename plugins/{ => genshin}/abyss.py (100%) rename plugins/{ => genshin}/adduser.py (100%) rename plugins/{ => genshin}/artifact_rate.py (100%) rename plugins/{ => genshin}/daily_note.py (100%) rename plugins/{ => genshin}/gacha/__init__.py (100%) rename plugins/{ => genshin}/gacha/gacha.py (98%) rename plugins/{ => genshin}/gacha/wish.py (100%) rename plugins/{ => genshin}/help.py (100%) rename plugins/{ => genshin}/ledger.py (100%) rename plugins/{ => genshin}/map/__init__.py (100%) rename plugins/{ => genshin}/map/map.py (100%) rename plugins/{ => genshin}/map/model.py (100%) rename plugins/{ => genshin}/post.py (100%) rename plugins/{ => genshin}/sign.py (100%) rename plugins/{ => genshin}/strategy.py (100%) rename plugins/{ => genshin}/uid.py (100%) rename plugins/{ => genshin}/weapon.py (100%) rename plugins/{ => genshin}/wiki.py (100%) rename plugins/{ => system}/admin.py (100%) rename plugins/{ => system}/errorhandler.py (100%) rename plugins/{ => system}/inline.py (100%) rename plugins/{ => system}/start.py (100%) diff --git a/plugins/abyss.py b/plugins/genshin/abyss.py similarity index 100% rename from plugins/abyss.py rename to plugins/genshin/abyss.py diff --git a/plugins/adduser.py b/plugins/genshin/adduser.py similarity index 100% rename from plugins/adduser.py rename to plugins/genshin/adduser.py diff --git a/plugins/artifact_rate.py b/plugins/genshin/artifact_rate.py similarity index 100% rename from plugins/artifact_rate.py rename to plugins/genshin/artifact_rate.py diff --git a/plugins/daily_note.py b/plugins/genshin/daily_note.py similarity index 100% rename from plugins/daily_note.py rename to plugins/genshin/daily_note.py diff --git a/plugins/gacha/__init__.py b/plugins/genshin/gacha/__init__.py similarity index 100% rename from plugins/gacha/__init__.py rename to plugins/genshin/gacha/__init__.py diff --git a/plugins/gacha/gacha.py b/plugins/genshin/gacha/gacha.py similarity index 98% rename from plugins/gacha/gacha.py rename to plugins/genshin/gacha/gacha.py index ff9d8e9..7d5316d 100644 --- a/plugins/gacha/gacha.py +++ b/plugins/genshin/gacha/gacha.py @@ -9,7 +9,7 @@ from core.template import TemplateService from logger import Log from models.apihelper.gacha import GachaInfo from plugins.base import BasePlugins -from plugins.gacha.wish import WishCountInfo, get_one +from plugins.genshin.gacha.wish import WishCountInfo, get_one from utils.bot import get_all_args from utils.decorators.error import error_callable from utils.decorators.restricts import restricts diff --git a/plugins/gacha/wish.py b/plugins/genshin/gacha/wish.py similarity index 100% rename from plugins/gacha/wish.py rename to plugins/genshin/gacha/wish.py diff --git a/plugins/help.py b/plugins/genshin/help.py similarity index 100% rename from plugins/help.py rename to plugins/genshin/help.py diff --git a/plugins/ledger.py b/plugins/genshin/ledger.py similarity index 100% rename from plugins/ledger.py rename to plugins/genshin/ledger.py diff --git a/plugins/map/__init__.py b/plugins/genshin/map/__init__.py similarity index 100% rename from plugins/map/__init__.py rename to plugins/genshin/map/__init__.py diff --git a/plugins/map/map.py b/plugins/genshin/map/map.py similarity index 100% rename from plugins/map/map.py rename to plugins/genshin/map/map.py diff --git a/plugins/map/model.py b/plugins/genshin/map/model.py similarity index 100% rename from plugins/map/model.py rename to plugins/genshin/map/model.py diff --git a/plugins/post.py b/plugins/genshin/post.py similarity index 100% rename from plugins/post.py rename to plugins/genshin/post.py diff --git a/plugins/sign.py b/plugins/genshin/sign.py similarity index 100% rename from plugins/sign.py rename to plugins/genshin/sign.py diff --git a/plugins/strategy.py b/plugins/genshin/strategy.py similarity index 100% rename from plugins/strategy.py rename to plugins/genshin/strategy.py diff --git a/plugins/uid.py b/plugins/genshin/uid.py similarity index 100% rename from plugins/uid.py rename to plugins/genshin/uid.py diff --git a/plugins/weapon.py b/plugins/genshin/weapon.py similarity index 100% rename from plugins/weapon.py rename to plugins/genshin/weapon.py diff --git a/plugins/wiki.py b/plugins/genshin/wiki.py similarity index 100% rename from plugins/wiki.py rename to plugins/genshin/wiki.py diff --git a/plugins/admin.py b/plugins/system/admin.py similarity index 100% rename from plugins/admin.py rename to plugins/system/admin.py diff --git a/plugins/errorhandler.py b/plugins/system/errorhandler.py similarity index 100% rename from plugins/errorhandler.py rename to plugins/system/errorhandler.py diff --git a/plugins/inline.py b/plugins/system/inline.py similarity index 100% rename from plugins/inline.py rename to plugins/system/inline.py diff --git a/plugins/start.py b/plugins/system/start.py similarity index 100% rename from plugins/start.py rename to plugins/system/start.py diff --git a/utils/plugins/manager.py b/utils/plugins/manager.py index 98a82b8..f542306 100644 --- a/utils/plugins/manager.py +++ b/utils/plugins/manager.py @@ -29,7 +29,6 @@ class PluginsManager: self.exclude_list: List[str] = [] def refresh_list(self, plugin_paths): - self.plugin_list.clear() plugin_paths = glob(plugin_paths) for plugin_path in plugin_paths: if plugin_path.startswith('__'): diff --git a/utils/plugins/register.py b/utils/plugins/register.py index 6a99190..9009665 100644 --- a/utils/plugins/register.py +++ b/utils/plugins/register.py @@ -1,12 +1,13 @@ +from importlib import import_module from typing import Optional from telegram.ext import CommandHandler, MessageHandler, filters, CallbackQueryHandler, Application, InlineQueryHandler from logger import Log from plugins.base import NewChatMembersHandler -from plugins.errorhandler import error_handler -from plugins.inline import Inline -from plugins.start import start, ping, reply_keyboard_remove, unknown_command +from plugins.system.errorhandler import error_handler +from plugins.system.inline import Inline +from plugins.system.start import start, ping, reply_keyboard_remove, unknown_command from utils.plugins.manager import PluginsManager @@ -32,10 +33,10 @@ def register_plugin_handlers(application: Application): Log.info("正在加载插件管理器") plugins_manager = PluginsManager() - plugins_manager.refresh_list("./plugins/*") + plugins_manager.refresh_list("./plugins/genshin/*") # 忽略内置模块 - plugins_manager.add_exclude(["start", "base", "auth", "inline", "errorhandler"]) + # plugins_manager.add_exclude(["start", "auth", "inline", "errorhandler"]) Log.info("加载插件管理器正在加载插件") plugins_manager.import_module() @@ -57,4 +58,6 @@ def register_plugin_handlers(application: Application): application.add_handler(MessageHandler(filters.COMMAND & filters.ChatType.PRIVATE, unknown_command)) application.add_error_handler(error_handler, block=False) + import_module(f"plugins.system.admin") + Log.info("插件加载成功") diff --git a/utils/service/inject.py b/utils/service/inject.py index 7cec081..98d1ecf 100644 --- a/utils/service/inject.py +++ b/utils/service/inject.py @@ -3,7 +3,7 @@ from functools import wraps from logger import Log from models.types import Func -from utils.service.manager import ServiceDict +from utils.service.manager import ServicesDict def get_injections(func: Func): @@ -21,7 +21,7 @@ def get_injections(func: Func): for parameter_name, parameter in signature.parameters.items(): annotation = parameter.annotation class_name = annotation.__name__ - param = ServiceDict.get(class_name) + param = ServicesDict.get(class_name) if param is not None: injections.setdefault(parameter_name, param) return injections diff --git a/utils/service/manager.py b/utils/service/manager.py index f25a552..a6d60ea 100644 --- a/utils/service/manager.py +++ b/utils/service/manager.py @@ -10,15 +10,15 @@ from utils.aiobrowser import AioBrowser from utils.mysql import MySQL from utils.redisdb import RedisDB -ServiceFunctions: List[Func] = [] -ServiceDict: Dict[str, Func] = {} +ServicesFunctions: List[Func] = [] +ServicesDict: Dict[str, Func] = {} def listener_service(): """监听服务""" def decorator(func: Func): - ServiceFunctions.append( + ServicesFunctions.append( func ) return func @@ -31,16 +31,16 @@ class ServicesManager: self.browser = browser self.redis = redis self.mysql = mysql - self.app_list: List[str] = [] + self.services_list: List[str] = [] self.exclude_list: List[str] = [] def refresh_list(self, app_paths): - self.app_list.clear() + self.services_list.clear() app_paths = glob(app_paths) for app_path in app_paths: if os.path.isdir(app_path): app_path = os.path.basename(app_path) - self.app_list.append(app_path) + self.services_list.append(app_path) def add_exclude(self, exclude: Union[str, List[str]]): if isinstance(exclude, str): @@ -51,21 +51,21 @@ class ServicesManager: raise TypeError def import_module(self): - for app_name in self.app_list: - if app_name not in self.exclude_list: + for services_name in self.services_list: + if services_name not in self.exclude_list: try: - import_module(f"apps.{app_name}") + import_module(f"apps.{services_name}") except ImportError as exc: - Log.warning(f"Service模块 {app_name} 导入失败", exc) + Log.warning(f"Service模块 {services_name} 导入失败", exc) except ImportWarning as exc: - Log.warning(f"Service模块 {app_name} 加载成功但有警告", exc) + Log.warning(f"Service模块 {services_name} 加载成功但有警告", exc) except Exception as exc: - Log.warning(f"Service模块 {app_name} 加载失败", exc) + Log.warning(f"Service模块 {services_name} 加载失败", exc) else: - Log.debug(f"Service模块 {app_name} 加载成功") + Log.debug(f"Service模块 {services_name} 加载成功") def add_service(self): - for func in ServiceFunctions: + for func in ServicesFunctions: if callable(func): kwargs = {} try: @@ -91,7 +91,7 @@ class ServicesManager: try: handlers_list = func(**kwargs) class_name = handlers_list.__class__.__name__ - ServiceDict.setdefault(class_name, handlers_list) + ServicesDict.setdefault(class_name, handlers_list) except BaseException as exc: Log.error("初始化Service失败", exc) finally: