From 7095d975ac37e4d451b1d73ccf3afb63a11d1191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Thu, 1 Sep 2022 17:04:06 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E4=BC=98=E5=8C=96=E6=8A=BD?= =?UTF-8?q?=E5=8D=A1=E7=9A=84=E6=A0=87=E9=A2=98=E6=98=BE=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/gacha/gacha.py | 18 ++++++++++++++++-- resources/genshin/gacha/gacha.css | 4 ++++ resources/genshin/gacha/gacha.html | 6 +++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/plugins/genshin/gacha/gacha.py b/plugins/genshin/gacha/gacha.py index 7d5316d1..87ab236f 100644 --- a/plugins/genshin/gacha/gacha.py +++ b/plugins/genshin/gacha/gacha.py @@ -1,5 +1,7 @@ import os +import re +from bs4 import BeautifulSoup from pyppeteer import launch from telegram import Update from telegram.constants import ChatAction @@ -88,12 +90,24 @@ class Gacha(BasePlugins): if user_gacha_count is None: user_gacha_count = user_gacha[gacha_id] = WishCountInfo(user_id=user.id) # 用户数据储存和处理 + title = gacha_info["title"] + re_color = re.search(r"", title, flags=0) + if re_color is None: + title_html = BeautifulSoup(title, "lxml") + pool_name = title_html.text + Log.warning(f"卡池信息 title 提取 color 失败 title[{title}]") + else: + color = re_color.group(1) + title_html = BeautifulSoup(title, "lxml") + title_html.color.name = "span" + title_html.span["style"] = f"color:#{color};" + pool_name = title_html.p await message.reply_chat_action(ChatAction.TYPING) data = { "_res_path": f"file://{self.resources_dir}", "name": f"{user.full_name}", "info": gacha_name, - "poolName": gacha_info["title"], + "poolName": pool_name, "items": [], } for _ in range(10): @@ -116,7 +130,7 @@ class Gacha(BasePlugins): await message.reply_chat_action(ChatAction.UPLOAD_PHOTO) # 因为 gacha_info["title"] 返回的是 HTML 标签 尝试关闭自动转义 png_data = await self.template_service.render('genshin/gacha', "gacha.html", data, - {"width": 1157, "height": 603}, False, False) + {"width": 1157, "height": 603}, False, auto_escape=True) reply_message = await message.reply_photo(png_data) if filters.ChatType.GROUPS.filter(message): diff --git a/resources/genshin/gacha/gacha.css b/resources/genshin/gacha/gacha.css index 158776f4..1f4eb24c 100644 --- a/resources/genshin/gacha/gacha.css +++ b/resources/genshin/gacha/gacha.css @@ -54,6 +54,10 @@ body { z-index: 9999; } +.poor-info span { + font-size: 50px; +} + .poor-bing { position: fixed; top: 85px; diff --git a/resources/genshin/gacha/gacha.html b/resources/genshin/gacha/gacha.html index f8304c15..1b8fdd94 100644 --- a/resources/genshin/gacha/gacha.html +++ b/resources/genshin/gacha/gacha.html @@ -10,7 +10,11 @@
{{name}}
{{info}}
-
{{poolName}}
+
+ {% autoescape off %} + {{poolName}} + {% endautoescape %} +
{% for item in items %}