From ee28df892f6ef0755ae6329db78494e8e12bd16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Sat, 17 Jun 2023 22:07:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E4=B8=BA=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E9=94=99=E8=AF=AF=E8=BD=AC=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=85=B3=20(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/utils/error_reply.py | 11 ++++++++--- gsuid_core/utils/plugins_config/config_default.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gsuid_core/utils/error_reply.py b/gsuid_core/utils/error_reply.py index 1058bc8..add7165 100644 --- a/gsuid_core/utils/error_reply.py +++ b/gsuid_core/utils/error_reply.py @@ -5,6 +5,7 @@ from PIL import Image, ImageDraw from gsuid_core.utils.fonts.fonts import core_font from gsuid_core.utils.image.convert import convert_img +from gsuid_core.utils.plugins_config.gs_config import core_plugins_config from gsuid_core.utils.image.image_tools import ( get_color_bg, draw_center_text_by_line, @@ -27,6 +28,7 @@ UPDATE_HINT = '''更新失败!更多错误信息请查看控制台... >> [gs强行强制更新](超级危险)!''' TEXT_PATH = Path(__file__).parent / 'image' / 'texture2d' +is_pic_error = core_plugins_config.get_config('ChangeErrorToPic').data def get_error(retcode: Union[int, str]) -> str: @@ -76,10 +78,13 @@ def get_error_type(retcode: Union[int, str]) -> str: return 'Api错误' -async def get_error_img(retcode: Union[int, str]) -> bytes: +async def get_error_img(retcode: Union[int, str]) -> Union[bytes, str]: error_message = get_error(retcode) - error_type = get_error_type(retcode) - return await draw_error_img(retcode, error_message, error_type) + if is_pic_error: + error_type = get_error_type(retcode) + return await draw_error_img(retcode, error_message, error_type) + else: + return error_message async def draw_error_img( diff --git a/gsuid_core/utils/plugins_config/config_default.py b/gsuid_core/utils/plugins_config/config_default.py index 0b2ee6e..6ba2754 100644 --- a/gsuid_core/utils/plugins_config/config_default.py +++ b/gsuid_core/utils/plugins_config/config_default.py @@ -53,4 +53,5 @@ CONIFG_DEFAULT: Dict[str, GSC] = { 'RandomText': GsStrConfig( '随机字符串列表', '随机字符串列表', 'abcdefghijklmnopqrstuvwxyz' ), + 'ChangeErrorToPic': GsBoolConfig('错误提示转换为图片', '将一部分报错提示转换为图片', True), }