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