mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
parent
264929e5cb
commit
63145ffee0
@ -11,6 +11,7 @@ from nonebot.compat import model_dump
|
||||
from nonebot_plugin_alconna import UniMessage, UniMsg
|
||||
from nonebot_plugin_uninfo import Uninfo
|
||||
from pydantic import BaseModel, create_model
|
||||
from tortoise.expressions import Q
|
||||
|
||||
from zhenxun.models.friend_user import FriendUser
|
||||
from zhenxun.models.goods_info import GoodsInfo
|
||||
@ -120,7 +121,7 @@ async def gold_rank(
|
||||
)
|
||||
data_list.append(
|
||||
[
|
||||
f"{i+1}",
|
||||
f"{i + 1}",
|
||||
(ava_bytes, 30, 30) if platform == "qq" else "",
|
||||
uid2name.get(user[0]),
|
||||
user[1],
|
||||
@ -405,17 +406,19 @@ class ShopManage:
|
||||
返回:
|
||||
str: 返回小
|
||||
"""
|
||||
if name == "神秘药水":
|
||||
return "你们看看就好啦,这是不可能卖给你们的~"
|
||||
if num < 0:
|
||||
return "购买的数量要大于0!"
|
||||
goods_list = await GoodsInfo.annotate().order_by("id").all()
|
||||
goods_list = [
|
||||
goods
|
||||
for goods in goods_list
|
||||
if goods.goods_limit_time > time.time() or goods.goods_limit_time == 0
|
||||
]
|
||||
goods_list = (
|
||||
await GoodsInfo.filter(
|
||||
Q(goods_limit_time__gte=time.time()) | Q(goods_limit_time=0)
|
||||
)
|
||||
.annotate()
|
||||
.order_by("id")
|
||||
.all()
|
||||
)
|
||||
if name.isdigit():
|
||||
if int(name) > len(goods_list) or int(name) <= 0:
|
||||
return "道具编号不存在..."
|
||||
goods = goods_list[int(name) - 1]
|
||||
elif filter_goods := [g for g in goods_list if g.goods_name == name]:
|
||||
goods = filter_goods[0]
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
from nonebot_plugin_htmlrender import template_to_pic
|
||||
from pydantic import BaseModel
|
||||
from tortoise.expressions import Q
|
||||
|
||||
from zhenxun.configs.config import BotConfig
|
||||
from zhenxun.configs.path_config import TEMPLATE_PATH
|
||||
@ -18,35 +20,57 @@ class GoodsItem(BaseModel):
|
||||
"""分区名称"""
|
||||
|
||||
|
||||
def get_limit_time(end_time: int):
|
||||
now = int(time.time())
|
||||
if now > end_time:
|
||||
return None
|
||||
current_datetime = datetime.fromtimestamp(now)
|
||||
end_datetime = datetime.fromtimestamp(end_time)
|
||||
time_difference = end_datetime - current_datetime
|
||||
total_seconds = time_difference.total_seconds()
|
||||
hours = int(total_seconds // 3600)
|
||||
minutes = int((total_seconds % 3600) // 60)
|
||||
return f"{hours}:{minutes}"
|
||||
|
||||
|
||||
def get_discount(price: int, discount: float):
|
||||
return None if discount == 1.0 else int(price * discount)
|
||||
|
||||
|
||||
async def html_image() -> bytes:
|
||||
"""构建图片"""
|
||||
goods_list: list[tuple[int, GoodsInfo]] = [
|
||||
(i + 1, goods)
|
||||
for i, goods in enumerate(await GoodsInfo.get_all_goods())
|
||||
if goods.goods_limit_time == 0 or time.time() < goods.goods_limit_time
|
||||
]
|
||||
goods_list = (
|
||||
await GoodsInfo.filter(
|
||||
Q(goods_limit_time__gte=time.time()) | Q(goods_limit_time=0)
|
||||
)
|
||||
.annotate()
|
||||
.order_by("id")
|
||||
.all()
|
||||
)
|
||||
partition_dict: dict[str, list[dict]] = {}
|
||||
for goods in goods_list:
|
||||
if not goods[1].partition:
|
||||
goods[1].partition = "默认分区"
|
||||
if goods[1].partition not in partition_dict:
|
||||
partition_dict[goods[1].partition] = []
|
||||
for idx, goods in enumerate(goods_list):
|
||||
if not goods.partition:
|
||||
goods.partition = "默认分区"
|
||||
if goods.partition not in partition_dict:
|
||||
partition_dict[goods.partition] = []
|
||||
icon = None
|
||||
if goods[1].icon:
|
||||
path = ICON_PATH / goods[1].icon
|
||||
if goods.icon:
|
||||
path = ICON_PATH / goods.icon
|
||||
if path.exists():
|
||||
icon = (
|
||||
"data:image/png;base64,"
|
||||
f"{BuildImage.open(ICON_PATH / goods[1].icon).pic2bs4()[9:]}"
|
||||
f"{BuildImage.open(ICON_PATH / goods.icon).pic2bs4()[9:]}"
|
||||
)
|
||||
partition_dict[goods[1].partition].append(
|
||||
partition_dict[goods.partition].append(
|
||||
{
|
||||
"id": goods[0],
|
||||
"price": goods[1].goods_price,
|
||||
"daily_limit": goods[1].daily_limit or "∞",
|
||||
"name": goods[1].goods_name,
|
||||
"id": idx + 1,
|
||||
"price": goods.goods_price,
|
||||
"discount_price": get_discount(goods.goods_price, goods.goods_discount),
|
||||
"limit_time": get_limit_time(goods.goods_limit_time),
|
||||
"daily_limit": goods.daily_limit or "∞",
|
||||
"name": goods.goods_name,
|
||||
"icon": icon,
|
||||
"description": goods[1].goods_description,
|
||||
"description": goods.goods_description,
|
||||
}
|
||||
)
|
||||
data_list = [
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import time
|
||||
|
||||
from tortoise.expressions import Q
|
||||
|
||||
from zhenxun.configs.path_config import IMAGE_PATH
|
||||
from zhenxun.models.goods_info import GoodsInfo
|
||||
from zhenxun.utils._build_image import BuildImage
|
||||
@ -14,17 +16,19 @@ async def normal_image() -> bytes:
|
||||
返回:
|
||||
BuildImage: 商店图片
|
||||
"""
|
||||
goods_lst = await GoodsInfo.get_all_goods()
|
||||
h = 10
|
||||
_list: list[GoodsInfo] = [
|
||||
goods
|
||||
for goods in goods_lst
|
||||
if goods.goods_limit_time == 0 or time.time() < goods.goods_limit_time
|
||||
]
|
||||
goods_list = (
|
||||
await GoodsInfo.filter(
|
||||
Q(goods_limit_time__gte=time.time()) | Q(goods_limit_time=0)
|
||||
)
|
||||
.annotate()
|
||||
.order_by("id")
|
||||
.all()
|
||||
)
|
||||
# A = BuildImage(1100, h, color="#f9f6f2")
|
||||
total_n = 0
|
||||
image_list = []
|
||||
for idx, goods in enumerate(_list):
|
||||
for idx, goods in enumerate(goods_list):
|
||||
name_image = BuildImage(
|
||||
580, 40, font_size=25, color="#e67b6b", font="CJGaoDeGuo.otf"
|
||||
)
|
||||
|
||||
@ -7,6 +7,7 @@ from nonebot.adapters.onebot.v11 import Message, MessageSegment
|
||||
from nonebot_plugin_alconna import (
|
||||
At,
|
||||
AtAll,
|
||||
Button,
|
||||
CustomNode,
|
||||
Image,
|
||||
Reference,
|
||||
@ -37,6 +38,7 @@ MESSAGE_TYPE = (
|
||||
| Text
|
||||
| Voice
|
||||
| Video
|
||||
| Button
|
||||
)
|
||||
|
||||
|
||||
@ -58,9 +60,7 @@ class MessageUtils:
|
||||
config = nonebot.get_plugin_config(Config)
|
||||
message_list = []
|
||||
for msg in msg_list:
|
||||
if isinstance(msg, Image | Text | At | AtAll | Video | Voice):
|
||||
message_list.append(msg)
|
||||
elif isinstance(msg, str):
|
||||
if isinstance(msg, str):
|
||||
if msg.startswith("base64://"):
|
||||
message_list.append(Image(raw=BytesIO(base64.b64decode(msg[9:]))))
|
||||
elif msg.startswith("http://"):
|
||||
@ -85,6 +85,8 @@ class MessageUtils:
|
||||
message_list.append(Image(raw=msg))
|
||||
elif isinstance(msg, BuildImage):
|
||||
message_list.append(Image(raw=msg.pic2bytes()))
|
||||
else:
|
||||
message_list.append(msg)
|
||||
return message_list
|
||||
|
||||
@classmethod
|
||||
|
||||
Loading…
Reference in New Issue
Block a user