mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-24 21:50:01 +08:00
Compare commits
2
Commits
2580998ab8
...
5dced498f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5dced498f4 | ||
|
|
f76ae521d9 |
@@ -1,90 +0,0 @@
|
|||||||
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 THEMES_PATH
|
|
||||||
from zhenxun.models.goods_info import GoodsInfo
|
|
||||||
from zhenxun.utils._build_image import BuildImage
|
|
||||||
|
|
||||||
from .config import ICON_PATH
|
|
||||||
|
|
||||||
|
|
||||||
class GoodsItem(BaseModel):
|
|
||||||
goods_list: list[dict]
|
|
||||||
"""商品列表"""
|
|
||||||
partition: str
|
|
||||||
"""分区名称"""
|
|
||||||
|
|
||||||
|
|
||||||
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 = (
|
|
||||||
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 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.icon:
|
|
||||||
path = ICON_PATH / goods.icon
|
|
||||||
if path.exists():
|
|
||||||
icon = (
|
|
||||||
"data:image/png;base64,"
|
|
||||||
f"{BuildImage.open(ICON_PATH / goods.icon).pic2bs4()[9:]}"
|
|
||||||
)
|
|
||||||
partition_dict[goods.partition].append(
|
|
||||||
{
|
|
||||||
"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.goods_description,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
data_list = [
|
|
||||||
GoodsItem(goods_list=value, partition=partition)
|
|
||||||
for partition, value in partition_dict.items()
|
|
||||||
]
|
|
||||||
template_dir = THEMES_PATH / "default" / "templates" / "shop"
|
|
||||||
return await template_to_pic(
|
|
||||||
template_path=str(template_dir.absolute()),
|
|
||||||
template_name="main.html",
|
|
||||||
templates={"name": BotConfig.self_nickname, "data_list": data_list},
|
|
||||||
pages={
|
|
||||||
"viewport": {"width": 850, "height": 1024},
|
|
||||||
"base_url": f"file://{THEMES_PATH.parent.absolute()}",
|
|
||||||
},
|
|
||||||
wait=2,
|
|
||||||
)
|
|
||||||
@@ -23,9 +23,9 @@ from .config import (
|
|||||||
lik2relation,
|
lik2relation,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(level2attitude) == len(lik2level) == len(lik2relation), (
|
assert (
|
||||||
"好感度态度、等级、关系长度不匹配!"
|
len(level2attitude) == len(lik2level) == len(lik2relation)
|
||||||
)
|
), "好感度态度、等级、关系长度不匹配!"
|
||||||
|
|
||||||
AVA_URL = "http://q1.qlogo.cn/g?b=qq&nk={}&s=160"
|
AVA_URL = "http://q1.qlogo.cn/g?b=qq&nk={}&s=160"
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ async def _(session: EventSession, arparma: Arparma):
|
|||||||
await MessageUtils.build_message("重载完成!").send(reply_to=True)
|
await MessageUtils.build_message("重载完成!").send(reply_to=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@scheduler.scheduled_job(
|
@scheduler.scheduled_job(
|
||||||
"interval",
|
"interval",
|
||||||
seconds=Config.get_config("reload_setting", "AUTO_RELOAD_TIME", 180),
|
seconds=Config.get_config("reload_setting", "AUTO_RELOAD_TIME", 180),
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
from . import widgets
|
from . import widgets
|
||||||
from .core.layout import LayoutBuilder
|
from .core.layout import LayoutBuilder
|
||||||
from .core.markdown import MarkdownBuilder
|
from .core.markdown import MarkdownBuilder
|
||||||
|
|||||||
@@ -34,4 +34,3 @@ class PluginMenuBuilder(BaseBuilder[PluginMenuData]):
|
|||||||
for category in categories:
|
for category in categories:
|
||||||
self.add_category(category)
|
self.add_category(category)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|||||||
@@ -283,6 +283,3 @@ class ImageTemplate:
|
|||||||
width = max(width, w)
|
width = max(width, w)
|
||||||
height += h
|
height += h
|
||||||
return width, height
|
return width, height
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user