From cc77f82e5cce4fa42cddce6b67f4ae51cf516ac7 Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Mon, 7 Oct 2024 01:53:34 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98,=20=E9=94=81=E5=AE=9A=E4=BE=9D?= =?UTF-8?q?=E8=B5=96,=20=E6=8F=90=E5=89=8D=E5=8A=A0=E8=BD=BD`core=5Fcomman?= =?UTF-8?q?d`=E6=8F=92=E4=BB=B6=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/client.py | 2 +- .../core_command/core_restart/__init__.py | 4 ++-- .../core_command/core_status/__init__.py | 2 +- .../core_command/core_update/__init__.py | 11 +++++----- .../core_command/core_user/__init__.py | 4 ++-- .../core_command/core_webconsole/__init__.py | 4 +++- .../core_command/install_plugins/__init__.py | 8 ++++---- .../core_command/user_login/__init__.py | 15 +++++++------- gsuid_core/server.py | 20 ++++++++++++------- gsuid_core/sv.py | 7 ++++--- pdm.lock | 8 ++++---- poetry.lock | 8 ++++---- pyproject.toml | 4 ++-- requirements.txt | 2 +- 14 files changed, 55 insertions(+), 44 deletions(-) diff --git a/gsuid_core/client.py b/gsuid_core/client.py index 6709741..4250c25 100644 --- a/gsuid_core/client.py +++ b/gsuid_core/client.py @@ -53,7 +53,7 @@ class GsClient: bot_id='console', # bot_id='qqgroup', bot_self_id='511love51', - user_type='group', + user_type='direct', user_pm=0, group_id=group_id, user_id=user_id, diff --git a/gsuid_core/plugins/core_command/core_restart/__init__.py b/gsuid_core/plugins/core_command/core_restart/__init__.py index a74249a..c5ffbe2 100644 --- a/gsuid_core/plugins/core_command/core_restart/__init__.py +++ b/gsuid_core/plugins/core_command/core_restart/__init__.py @@ -46,7 +46,7 @@ async def check_msg(): logger.warning('遗留信息检查失败!') -@sv_core_config.on_fullmatch(('core重启', 'gs重启')) +@sv_core_config.on_fullmatch(('core重启', 'gs重启'), block=True) async def send_restart_msg(bot: Bot, ev: Event): await bot.logger.warning('开始执行[重启]') if ev.group_id: @@ -61,7 +61,7 @@ async def send_restart_msg(bot: Bot, ev: Event): ) -@sv_core_config.on_fullmatch(('core关闭', 'Core关闭')) +@sv_core_config.on_fullmatch(('core关闭', 'Core关闭'), block=True) async def send_shutdown_msg(bot: Bot, ev: Event): await bot.logger.warning('开始执行[关闭]') await bot.send('正在执行[gs关闭Core]...') diff --git a/gsuid_core/plugins/core_command/core_status/__init__.py b/gsuid_core/plugins/core_command/core_status/__init__.py index 8b49395..483d8ae 100644 --- a/gsuid_core/plugins/core_command/core_status/__init__.py +++ b/gsuid_core/plugins/core_command/core_status/__init__.py @@ -44,7 +44,7 @@ async def scheduled_save_global_val(): await count_group_user() -@sv_core_status.on_command(('core状态', 'Core状态')) +@sv_core_status.on_command(('core状态', 'Core状态'), block=True) async def send_core_status_msg(bot: Bot, ev: Event): day = ev.text.strip() if day and day.isdigit(): diff --git a/gsuid_core/plugins/core_command/core_update/__init__.py b/gsuid_core/plugins/core_command/core_update/__init__.py index 55252a2..8f1edb6 100644 --- a/gsuid_core/plugins/core_command/core_update/__init__.py +++ b/gsuid_core/plugins/core_command/core_update/__init__.py @@ -16,7 +16,7 @@ from gsuid_core.utils.plugins_update._plugins import ( sv_core_config = SV('Core管理', pm=0) -@sv_core_config.on_fullmatch(('core更新', 'core强制更新')) +@sv_core_config.on_fullmatch(('core更新', 'core强制更新'), block=True) async def send_core_update_msg(bot: Bot, ev: Event): logger.info('开始执行[更新] 早柚核心') if '强制' in ev.command: @@ -27,7 +27,7 @@ async def send_core_update_msg(bot: Bot, ev: Event): await bot.send(log_list) -@sv_core_config.on_command(('core设置代理')) +@sv_core_config.on_command(('core设置代理'), block=True) async def send_core_set_proxy(bot: Bot, ev: Event): logger.info('开始执行[设置代理]') proxy_url = ev.text.strip() if ev.text else '' @@ -39,7 +39,7 @@ async def send_core_set_proxy(bot: Bot, ev: Event): ) -@sv_core_config.on_command(('core应用设置代理')) +@sv_core_config.on_command(('core应用设置代理'), block=True) async def send_core_update_proxy(bot: Bot, ev: Event): logger.info('开始执行[应用设置代理]') proxy = ev.text if ev.text else None @@ -53,7 +53,7 @@ async def send_core_update_proxy(bot: Bot, ev: Event): await bot.send(log_list) -@sv_core_config.on_fullmatch(('core更新依赖')) +@sv_core_config.on_fullmatch(('core更新依赖'), block=True) async def send_core_poetry_install(bot: Bot, ev: Event): logger.info('开始执行[更新] 早柚核心依赖') retcode = await asyncio.to_thread(run_install) @@ -68,7 +68,8 @@ async def send_core_poetry_install(bot: Bot, ev: Event): 'core强制全部更新', 'core强行强制全部更新', 'core全部强行强制更新', - ) + ), + block=True, ) async def send_core_all_update_msg(bot: Bot, ev: Event): logger.info('开始执行[更新] 全部更新') diff --git a/gsuid_core/plugins/core_command/core_user/__init__.py b/gsuid_core/plugins/core_command/core_user/__init__.py index 0987bd8..d3784ea 100644 --- a/gsuid_core/plugins/core_command/core_user/__init__.py +++ b/gsuid_core/plugins/core_command/core_user/__init__.py @@ -11,7 +11,7 @@ core_user_info = SV('core用户信息') core_user_msg = SV('core信息确认') -@core_user_info.on_fullmatch(('绑定信息')) +@core_user_info.on_fullmatch(('绑定信息'), block=True) async def send_bind_card(bot: Bot, ev: Event): await bot.logger.info('开始执行[查询用户绑定状态]') im = await get_user_card(ev.bot_id, ev) @@ -19,7 +19,7 @@ async def send_bind_card(bot: Bot, ev: Event): await bot.send(im) -@core_user_msg.on_fullmatch(('给我发消息')) +@core_user_msg.on_fullmatch(('给我发消息'), block=True) async def send_direct_msg(bot: Bot, ev: Event): logger.info('开始执行[给我发消息]') messages = [ diff --git a/gsuid_core/plugins/core_command/core_webconsole/__init__.py b/gsuid_core/plugins/core_command/core_webconsole/__init__.py index 4de26fc..0a77b5c 100644 --- a/gsuid_core/plugins/core_command/core_webconsole/__init__.py +++ b/gsuid_core/plugins/core_command/core_webconsole/__init__.py @@ -14,7 +14,9 @@ from .drop_table import drop_web_table core_web = SV('core网页控制台管理', pm=0, area='DIRECT') -@core_web.on_fullmatch(('core清除网页控制台密码', 'core重置网页控制台密码')) +@core_web.on_fullmatch( + ('core清除网页控制台密码', 'core重置网页控制台密码'), block=True +) async def reset_web_password(bot: Bot, ev: Event): pw = generate_random_string() try: diff --git a/gsuid_core/plugins/core_command/install_plugins/__init__.py b/gsuid_core/plugins/core_command/install_plugins/__init__.py index 29d9ed6..13c96d5 100644 --- a/gsuid_core/plugins/core_command/install_plugins/__init__.py +++ b/gsuid_core/plugins/core_command/install_plugins/__init__.py @@ -13,7 +13,7 @@ from gsuid_core.utils.plugins_update._plugins import ( sv_core_install_plugins = SV('core管理插件', pm=0) -@sv_core_install_plugins.on_prefix(('core卸载插件')) +@sv_core_install_plugins.on_prefix(('core卸载插件'), block=True) async def send_plugins_uninstall(bot: Bot, ev: Event): if not ev.text: return await bot.send( @@ -40,7 +40,7 @@ async def send_plugins_uninstall(bot: Bot, ev: Event): await bot.send('已取消删除!') -@sv_core_install_plugins.on_prefix(('core安装插件')) +@sv_core_install_plugins.on_prefix(('core安装插件'), block=True) async def send_plugins_install(bot: Bot, ev: Event): plugins = await get_plugins_url(ev.text.strip().lower()) if not plugins: @@ -53,7 +53,7 @@ async def send_plugins_install(bot: Bot, ev: Event): await bot.send(im) -@sv_core_install_plugins.on_fullmatch(('core刷新插件列表')) +@sv_core_install_plugins.on_fullmatch(('core刷新插件列表'), block=True) async def refresh_plugins_list(bot: Bot, ev: Event): _list = await refresh_list() if len(_list) <= 3: @@ -64,7 +64,7 @@ async def refresh_plugins_list(bot: Bot, ev: Event): @sv_core_install_plugins.on_prefix( - ('core更新插件', 'core强制更新插件', 'core强行强制更新插件') + ('core更新插件', 'core强制更新插件', 'core强行强制更新插件'), block=True ) async def send_update_msg(bot: Bot, ev: Event): await bot.send('开始更新...请稍等一段时间...') diff --git a/gsuid_core/plugins/core_command/user_login/__init__.py b/gsuid_core/plugins/core_command/user_login/__init__.py index 1f4498e..8e6b5b7 100644 --- a/gsuid_core/plugins/core_command/user_login/__init__.py +++ b/gsuid_core/plugins/core_command/user_login/__init__.py @@ -25,21 +25,21 @@ sv_core_user_addck = SV('添加CK', area='DIRECT') sv_data_manger = SV('用户数据管理', pm=0) -@sv_core_user_config.on_fullmatch(('刷新全部CK', '刷新全部ck')) +@sv_core_user_config.on_fullmatch(('刷新全部CK', '刷新全部ck'), block=True) async def send_refresh_all_ck_msg(bot: Bot, ev: Event): await bot.logger.info('开始执行[刷新全部CK]') im = await get_ck_by_all_stoken(ev.bot_id) await bot.send(im) -@sv_core_user_add.on_fullmatch(('刷新CK', '刷新ck')) +@sv_core_user_add.on_fullmatch(('刷新CK', '刷新ck'), block=True) async def send_refresh_ck_msg(bot: Bot, ev: Event): await bot.logger.info('开始执行[刷新CK]') im = await get_ck_by_stoken(ev.bot_id, ev.user_id) await bot.send(im) -@sv_data_manger.on_fullmatch(('校验全部Cookies')) +@sv_data_manger.on_fullmatch(('校验全部Cookies'), block=True) async def send_check_cookie(bot: Bot, ev: Event): user_list = await GsUser.get_all_user() invalid_user: List[GsUser] = [] @@ -93,7 +93,7 @@ async def send_check_cookie(bot: Bot, ev: Event): await asyncio.sleep(3 + random.randint(1, 3)) -@sv_data_manger.on_fullmatch(('校验全部Stoken')) +@sv_data_manger.on_fullmatch(('校验全部Stoken'), block=True) async def send_check_stoken(bot: Bot, ev: Event): user_list = await GsUser.get_all_user() invalid_user: List[GsUser] = [] @@ -162,7 +162,7 @@ async def _send_help(bot: Bot, im): ) -@sv_core_user_qrcode_login.on_fullmatch(('扫码登陆', '扫码登录')) +@sv_core_user_qrcode_login.on_fullmatch(('扫码登陆', '扫码登录'), block=True) async def send_qrcode_login(bot: Bot, ev: Event): await bot.logger.info('开始执行[扫码登陆]') uid_list = await get_all_bind_uid(ev.bot_id, ev.user_id) @@ -182,7 +182,7 @@ async def send_qrcode_login(bot: Bot, ev: Event): await bot.send(im) -@sv_core_user_addck.on_prefix(('添加')) +@sv_core_user_addck.on_prefix(('添加'), block=True) async def send_add_ck_msg(bot: Bot, ev: Event): im, status = await deal_ck(ev.bot_id, ev.text, ev.user_id) if status: @@ -196,7 +196,8 @@ async def send_add_ck_msg(bot: Bot, ev: Event): 'mys设备登录', 'mys设备登陆', 'mys绑定设备', - ) + ), + block=True, ) async def send_add_device_msg(bot: Bot, ev: Event): try: diff --git a/gsuid_core/server.py b/gsuid_core/server.py index 94abd6a..52b0349 100644 --- a/gsuid_core/server.py +++ b/gsuid_core/server.py @@ -12,12 +12,8 @@ from fastapi import WebSocket from gsuid_core.bot import _Bot from gsuid_core.logger import logger +from gsuid_core.utils.plugins_update._plugins import check_start_tool from gsuid_core.utils.plugins_config.gs_config import core_plugins_config -from gsuid_core.utils.plugins_update._plugins import ( - check_start_tool, - sync_get_plugin_url, - sync_change_plugin_url, -) auto_install_dep: bool = core_plugins_config.get_config('AutoInstallDep').data auto_update_dep: bool = core_plugins_config.get_config('AutoUpdateDep').data @@ -63,8 +59,16 @@ class GsServer: get_installed_dependencies() sys.path.append(str(Path(__file__).parents[1])) plug_path = Path(__file__).parent / 'plugins' + + # 优先加载core_command + plug_path_list = list(plug_path.iterdir()) + core_command_path = plug_path / 'core_command' + if core_command_path in plug_path_list: + plug_path_list.remove(core_command_path) + plug_path_list.insert(0, core_command_path) + # 遍历插件文件夹内所有文件 - for plugin in plug_path.iterdir(): + for plugin in plug_path_list: if plugin.stem.startswith('_'): continue # 如果发现文件夹,则视为插件包 @@ -97,7 +101,8 @@ class GsServer: elif plugin.suffix == '.py': importlib.import_module(f'plugins.{plugin.name[:-3]}') - '''trick''' + '''trick 注释掉''' + ''' if plugin.stem in ['StarRailUID', 'ArknightsUID']: logger.info('[BAI] 检测是否存在失效仓库...') origin_url = sync_get_plugin_url(plugin) @@ -110,6 +115,7 @@ class GsServer: new_url = origin_url.replace('qwerdvd', 'baiqwerdvd') logger.success(f'[BAI] 替换新仓库地址成功: {new_url}') sync_change_plugin_url(plugin, new_url) + ''' '''导入成功''' logger.success(f'插件{plugin.stem}导入成功!') diff --git a/gsuid_core/sv.py b/gsuid_core/sv.py index 83f352f..a69be7e 100644 --- a/gsuid_core/sv.py +++ b/gsuid_core/sv.py @@ -101,9 +101,10 @@ class Plugins: if isinstance(prefix, str): prefix = [prefix] if allow_empty_prefix is None: - if '' in prefix: - prefix.remove('') - if prefix: + _pf = prefix + force_prefix + if '' in _pf: + _pf.remove('') + if _pf: allow_empty_prefix = False else: allow_empty_prefix = True diff --git a/pdm.lock b/pdm.lock index 6508ad9..37e3285 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default"] strategy = [] lock_version = "4.4.1" -content_hash = "sha256:79d7703eb8b2c942c03f2a487b3e7adf8813c9c390ca83e5dfd1b63d81ec4728" +content_hash = "sha256:a64cc47816b04cfd02dc5e49fb334402dc15bcaa9b172d99b8facd33c3f005f7" [[package]] name = "aioboto3" @@ -309,7 +309,7 @@ files = [ [[package]] name = "fastapi" -version = "0.114.0" +version = "0.112.2" requires_python = ">=3.8" summary = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" dependencies = [ @@ -318,8 +318,8 @@ dependencies = [ "typing-extensions>=4.8.0", ] files = [ - {file = "fastapi-0.114.0-py3-none-any.whl", hash = "sha256:fee75aa1b1d3d73f79851c432497e4394e413e1dece6234f68d3ce250d12760a"}, - {file = "fastapi-0.114.0.tar.gz", hash = "sha256:9908f2a5cc733004de6ca5e1412698f35085cefcbfd41d539245b9edf87b73c1"}, + {file = "fastapi-0.112.2-py3-none-any.whl", hash = "sha256:db84b470bd0e2b1075942231e90e3577e12a903c4dc8696f0d206a7904a7af1c"}, + {file = "fastapi-0.112.2.tar.gz", hash = "sha256:3d4729c038414d5193840706907a41839d839523da6ed0c2811f1168cac1798c"}, ] [[package]] diff --git a/poetry.lock b/poetry.lock index 8e7a917..5fccefa 100644 --- a/poetry.lock +++ b/poetry.lock @@ -626,13 +626,13 @@ reference = "mirrors" [[package]] name = "fastapi" -version = "0.113.0" +version = "0.112.2" description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" optional = false python-versions = ">=3.8" files = [ - {file = "fastapi-0.113.0-py3-none-any.whl", hash = "sha256:c8d364485b6361fb643d53920a18d58a696e189abcb901ec03b487e35774c476"}, - {file = "fastapi-0.113.0.tar.gz", hash = "sha256:b7cf9684dc154dfc93f8b718e5850577b529889096518df44defa41e73caf50f"}, + {file = "fastapi-0.112.2-py3-none-any.whl", hash = "sha256:db84b470bd0e2b1075942231e90e3577e12a903c4dc8696f0d206a7904a7af1c"}, + {file = "fastapi-0.112.2.tar.gz", hash = "sha256:3d4729c038414d5193840706907a41839d839523da6ed0c2811f1168cac1798c"}, ] [package.dependencies] @@ -2932,4 +2932,4 @@ reference = "mirrors" [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "1aa433aadcec3b9231c36a74ed5a86f1c438cd8bae902b7b66e615e62f1b0df0" +content-hash = "addb4ffcd2919b28ca0f7b741a1bcb44e2c1de993cd684b1ccb3fef13fbad011" diff --git a/pyproject.toml b/pyproject.toml index a7008d5..e608980 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ websockets = ">=13.1" loguru = ">=0.6.0" urllib3 = "^1.26.15" mpmath = "^1.3.0" -fastapi = "<0.114" +fastapi = "<0.112.3" apscheduler = "^3.10.1" aioboto3 = "^12.0.0" jinja2 = "^3.1.2" @@ -113,7 +113,7 @@ dependencies = [ "loguru<1.0.0,>=0.6.0", "urllib3<2.0.0,>=1.26.15", "mpmath<2.0.0,>=1.3.0", - "fastapi<0.114.1,>=0.97.0", + "fastapi<0.112.3,>=0.97.0", "apscheduler<4.0.0,>=3.10.1", "aioboto3<13.0.0,>=12.0.0", "jinja2<4.0.0,>=3.1.2", diff --git a/requirements.txt b/requirements.txt index 762fe02..bee382c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ dnspython==2.7.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0 email-validator==2.2.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" fastapi-amis-admin==0.7.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" fastapi-user-auth==0.7.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" -fastapi==0.113.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" +fastapi==0.112.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" frozenlist==1.4.1 ; python_full_version >= "3.8.1" and python_version < "4.0" gitdb==4.0.11 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" gitpython==3.1.43 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"