From b7f753ebb6d6fbf2f6482e1f708f0cc96e85d9b8 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Sun, 30 Oct 2022 18:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=BA=97=E7=AE=80=E4=BB=8B=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=A1=8C=E6=95=B0=EF=BC=8C=E6=A0=B9=E6=8D=AE=E6=96=87?= =?UTF-8?q?=E5=AD=97=E9=95=BF=E5=BA=A6=E8=87=AA=E5=8A=A8=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++ basic_plugins/shop/__init__.py | 11 ++- basic_plugins/shop/shop_handle/data_source.py | 70 ++++++++++++++----- plugins/sign_in/goods_register.py | 3 - utils/depends/__init__.py | 1 - 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 10980d06..e74e1380 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,15 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能 ## 更新 +### 2022/10/30 + +* 商店简介动态行数,根据文字长度自动换行 + +### 2022/10/28 + +* 为exec指令进行了SELECT语句适配,添加了查看所有表指令 [@pull/1155](https://github.com/HibiKier/zhenxun_bot/pull/1155) +* 修复复读 [@pull/1154](https://github.com/HibiKier/zhenxun_bot/pull/1154) + ### 2022/10/23 * 复读修改回图片下载 diff --git a/basic_plugins/shop/__init__.py b/basic_plugins/shop/__init__.py index 74df65bb..501ebfa4 100644 --- a/basic_plugins/shop/__init__.py +++ b/basic_plugins/shop/__init__.py @@ -1,5 +1,9 @@ -import nonebot from configs.config import Config +from nonebot import Driver +from utils.decorator.shop import shop_register +import nonebot + +driver: Driver = nonebot.get_driver() Config.add_plugin_config( @@ -12,3 +16,8 @@ Config.add_plugin_config( nonebot.load_plugins("basic_plugins/shop") + + +@driver.on_bot_connect +async def _(): + await shop_register.load_register() diff --git a/basic_plugins/shop/shop_handle/data_source.py b/basic_plugins/shop/shop_handle/data_source.py index 701eaaea..a1e9dd27 100644 --- a/basic_plugins/shop/shop_handle/data_source.py +++ b/basic_plugins/shop/shop_handle/data_source.py @@ -1,7 +1,7 @@ from PIL import Image from models.goods_info import GoodsInfo -from utils.image_utils import BuildImage +from utils.image_utils import BuildImage, text2image from utils.utils import is_number from configs.path_config import IMAGE_PATH from typing import Optional, Union, Tuple @@ -22,28 +22,22 @@ async def create_shop_help() -> str: :return: 图片base64 """ goods_lst = await GoodsInfo.get_all_goods() - idx = 1 _dc = {} font_h = BuildImage(0, 0).getsize("正")[1] h = 10 _list = [] for goods in goods_lst: if goods.goods_limit_time == 0 or time.time() < goods.goods_limit_time: - h += len(goods.goods_description.strip().split("\n")) * font_h + 80 _list.append(goods) - A = BuildImage(1100, h, color="#f9f6f2") - current_h = 0 + # A = BuildImage(1100, h, color="#f9f6f2") total_n = 0 - for goods in _list: - bk = BuildImage(1180, 80, font_size=15, color="#f9f6f2", font="CJGaoDeGuo.otf") - goods_image = BuildImage( - 600, 80, font_size=20, color="#a29ad6", font="CJGaoDeGuo.otf" - ) + image_list = [] + for idx, goods in enumerate(_list): name_image = BuildImage( 580, 40, font_size=25, color="#e67b6b", font="CJGaoDeGuo.otf" ) await name_image.atext( - (15, 0), f"{idx}.{goods.goods_name}", center_type="by_height" + (15, 0), f"{idx + 1}.{goods.goods_name}", center_type="by_height" ) await name_image.aline((380, -5, 280, 45), "#a29ad6", 5) await name_image.atext((390, 0), "售价:", center_type="by_height") @@ -70,14 +64,46 @@ async def create_shop_help() -> str: f" 金币", center_type="by_height", ) + des_image = None + font_img = BuildImage( + 600, 80, font_size=20, color="#a29ad6", font="CJGaoDeGuo.otf" + ) + p = font_img.getsize('简介:')[0] + 20 + if goods.goods_description: + des_list = goods.goods_description.split('\n') + desc = '' + for des in des_list: + if font_img.getsize(des)[0] > font_img.w - p - 20: + msg = '' + tmp = '' + for i in range(len(des)): + if font_img.getsize(tmp)[0] < font_img.w - p - 20: + tmp += des[i] + else: + msg += tmp + '\n' + tmp = des[i] + desc += msg + if tmp: + desc += tmp + else: + desc += des + '\n' + if desc[-1] == '\n': + desc = desc[:-1] + des_image = await text2image(desc, color="#a29ad6") + goods_image = BuildImage( + 600, (50 + des_image.h) if des_image else 50, font_size=20, color="#a29ad6", font="CJGaoDeGuo.otf" + ) + if des_image: + await goods_image.atext((15, 50), '简介:') + await goods_image.apaste(des_image, (p, 50)) await name_image.acircle_corner(5) await goods_image.apaste(name_image, (0, 5), True, center_type="by_width") - await goods_image.atext((15, 50), f"简介:{goods.goods_description}") await goods_image.acircle_corner(20) + bk = BuildImage(1180, (50 + des_image.h) if des_image else 50, font_size=15, color="#f9f6f2", font="CJGaoDeGuo.otf") if goods.icon and (icon_path / goods.icon).exists(): - icon = BuildImage(100, 100, background=icon_path / goods.icon) + icon = BuildImage(70, 70, background=icon_path / goods.icon) await bk.apaste(icon) - await bk.apaste(goods_image, (100, 0), alpha=True) + await bk.apaste(goods_image, (70, 0), alpha=True) n = 0 _w = 650 # 添加限时图标和时间 @@ -134,12 +160,20 @@ async def create_shop_help() -> str: total_n = n if n: await bk.aline((650, -1, 650 + n, -1), "#a29ad6", 5) - await bk.aline((650, 80, 650 + n, 80), "#a29ad6", 5) + # await bk.aline((650, 80, 650 + n, 80), "#a29ad6", 5) # 添加限时图标和时间 - idx += 1 - await A.apaste(bk, (0, current_h), True) - current_h += 90 + image_list.append(bk) + # await A.apaste(bk, (0, current_h), True) + # current_h += 90 + h = 0 + current_h = 0 + for img in image_list: + h += img.h + 10 + A = BuildImage(1100, h, color="#f9f6f2") + for img in image_list: + await A.apaste(img, (0, current_h), True) + current_h += img.h + 10 w = 950 if total_n: w += total_n diff --git a/plugins/sign_in/goods_register.py b/plugins/sign_in/goods_register.py index 74351813..545b5e0d 100644 --- a/plugins/sign_in/goods_register.py +++ b/plugins/sign_in/goods_register.py @@ -54,7 +54,4 @@ async def _(): print(user_id, group_id, '第一个使用后函数(after handle)') -@driver.on_bot_connect -async def _(): - await shop_register.load_register() diff --git a/utils/depends/__init__.py b/utils/depends/__init__.py index 0a7d200a..67e48794 100644 --- a/utils/depends/__init__.py +++ b/utils/depends/__init__.py @@ -8,7 +8,6 @@ from models.bag_user import BagUser from utils.message_builder import at from utils.utils import get_message_at, get_message_face, get_message_img, get_message_text from configs.config import Config -from utils.manager import plugins_manager def CostGold(gold: int):