mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
✨ 使用新版模板 (#313)
* 🔥 删除现有模板 * ✨ 自动克隆模板仓库 * 🔥 删除 identicon 相关代码 * 🚚 修改静态文件路径 * ✨ 使用新模板进行渲染 * ✨ 每次渲染都获取一次模板, 以应对实时更新 * ✨ TETR.IO 绑定图使用新模板 * 🚚 修改网络路径 * ✨ TOP 绑定图使用新模板 * ✨ TOS 绑定图使用新模板 * 🐛 防止截图超时 * 🐛 Pydantic V1 会把 float 转换成 int * ✏️ 模板字段名写错了 * ✨ 兼容 Pydantic V1 * ✨ TETR.IO 查询图使用新模板 * 🐛 在查询的用户没有历史记录时不去查询更多记录
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
from base64 import b64decode, b64encode
|
||||
from base64 import b64encode
|
||||
from io import BytesIO
|
||||
from typing import Literal, overload
|
||||
|
||||
from nonebot_plugin_userinfo import UserInfo # type: ignore[import-untyped]
|
||||
from PIL import Image
|
||||
|
||||
from ..templates import path
|
||||
from .browser import BrowserManager
|
||||
|
||||
|
||||
@overload
|
||||
async def get_avatar(user: UserInfo, scheme: Literal['Data URI'], default: str | None) -> str:
|
||||
@@ -53,29 +50,3 @@ async def get_avatar(user: UserInfo, scheme: Literal['Data URI', 'bytes'], defau
|
||||
raise TypeError("Can't get avatar format")
|
||||
return f'data:{Image.MIME[avatar_format]};base64,{b64encode(bot_avatar).decode()}'
|
||||
return bot_avatar
|
||||
|
||||
|
||||
async def generate_identicon(hash: str) -> bytes: # noqa: A002
|
||||
"""使用 identicon 生成头像
|
||||
|
||||
Args:
|
||||
hash (str): 提交给 identicon 的 hash 值
|
||||
|
||||
Returns:
|
||||
bytes: identicon 生成的 svg 的二进制数据
|
||||
"""
|
||||
browser = await BrowserManager.get_browser()
|
||||
async with await browser.new_page() as page:
|
||||
await page.add_script_tag(path=path / 'js/identicon.js')
|
||||
return b64decode(
|
||||
await page.evaluate(rf"""
|
||||
new Identicon('{hash}', {{
|
||||
background: [0x08, 0x0a, 0x06, 255],
|
||||
margin: 0.15,
|
||||
size: 300,
|
||||
brightness: 0.48,
|
||||
saturation: 0.65,
|
||||
format: 'svg',
|
||||
}}).toString();
|
||||
""")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user