From 1f4083f80144ad68be3c5a00e6d43036985c2a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Sun, 6 Aug 2023 22:20:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E6=B7=BB=E5=8A=A0`=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BE=9D=E8=B5=96`=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0PIL=E7=89=88=E6=9C=AC=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84`get=5Fsize`=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/help/draw_plugin_help.py | 6 +++++- gsuid_core/utils/image/convert.py | 8 +++++++- gsuid_core/utils/plugins_config/config_default.py | 1 + gsuid_core/utils/plugins_update/_plugins.py | 6 +++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gsuid_core/help/draw_plugin_help.py b/gsuid_core/help/draw_plugin_help.py index 0b78894..e057de0 100644 --- a/gsuid_core/help/draw_plugin_help.py +++ b/gsuid_core/help/draw_plugin_help.py @@ -64,7 +64,11 @@ async def get_help( bc = deepcopy(banner) bc_draw = ImageDraw.Draw(bc) bc_draw.text((30, 25), sv_name, text_color, font(35), 'lm') - size, _ = font(35).getsize(sv_name) + if hasattr(font, 'getsize'): + size, _ = font(35).getsize(sv_name) + else: + bbox = font(35).getbbox(sv_name) + size, _ = bbox[2] - bbox[0], bbox[3] - bbox[1] bc_draw.text((42 + size, 30), sv_desc, sub_color, font(20), 'lm') sv_img = easy_alpha_composite(sv_img, bc, (0, 10)) # sv_img.paste(bc, (0, 10), bc) diff --git a/gsuid_core/utils/image/convert.py b/gsuid_core/utils/image/convert.py index c70022a..bcff977 100644 --- a/gsuid_core/utils/image/convert.py +++ b/gsuid_core/utils/image/convert.py @@ -98,7 +98,13 @@ def get_str_size( continue line += i - size, _ = font.getsize(line) + + if hasattr(font, 'getsize'): + size, _ = font.getsize(line) + else: + bbox = font.getbbox(line) + size, _ = bbox[2] - bbox[0], bbox[3] - bbox[1] + if size >= limit: result += f'{line}\n' line = '' diff --git a/gsuid_core/utils/plugins_config/config_default.py b/gsuid_core/utils/plugins_config/config_default.py index 71affb3..a3f0d75 100644 --- a/gsuid_core/utils/plugins_config/config_default.py +++ b/gsuid_core/utils/plugins_config/config_default.py @@ -58,4 +58,5 @@ CONIFG_DEFAULT: Dict[str, GSC] = { 'TextToPicThreshold': GsStrConfig('文转图阈值', '开启自动转图后超过该阈值的文字会转成图片', '20'), 'EnableSpecificMsgId': GsBoolConfig('启用回复特殊ID', '如不知道请勿开启', False), 'SpecificMsgId': GsStrConfig('特殊返回消息ID', '如不知道请勿填写', ''), + 'AutoUpdateDep': GsBoolConfig('自动更新依赖', '更新插件时将会自动更新依赖', False), } diff --git a/gsuid_core/utils/plugins_update/_plugins.py b/gsuid_core/utils/plugins_update/_plugins.py index 7622ed1..bae53b6 100644 --- a/gsuid_core/utils/plugins_update/_plugins.py +++ b/gsuid_core/utils/plugins_update/_plugins.py @@ -9,11 +9,14 @@ from git.repo import Repo from git.exc import GitCommandError, NoSuchPathError, InvalidGitRepositoryError from gsuid_core.logger import logger +from gsuid_core.utils.plugins_config.gs_config import core_plugins_config from .api import CORE_PATH, PLUGINS_PATH, proxy_url, plugins_lib plugins_list: Dict[str, Dict[str, str]] = {} +is_update_dep = core_plugins_config.get_config('AutoUpdateDep').data + # 传入一个path对象 async def run_poetry_install(path: Optional[Path] = None) -> int: @@ -182,7 +185,8 @@ def update_from_git( if repo_like is None: repo = Repo(CORE_PATH) plugin_name = '早柚核心' - asyncio.create_task(run_poetry_install(CORE_PATH)) + if is_update_dep: + asyncio.create_task(run_poetry_install(CORE_PATH)) elif isinstance(repo_like, Path): repo = Repo(repo_like) plugin_name = repo_like.name