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 %}