mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
✨ 确保同一个账号生成的随机头像一致
This commit is contained in:
@@ -78,7 +78,7 @@ async def make_query_image(profile: UserProfile) -> bytes:
|
||||
await render(
|
||||
'v1/top/info',
|
||||
Info(
|
||||
user=People(avatar=get_avatar(), name=profile.user_name),
|
||||
user=People(avatar=get_avatar(profile.user_name), name=profile.user_name),
|
||||
today=InfoData(pps=today.pps, lpm=today.lpm, apm=today.apm, apl=today.apl),
|
||||
history=InfoData(pps=history.pps, lpm=history.lpm, apm=history.apm, apl=history.apl),
|
||||
),
|
||||
|
||||
@@ -223,7 +223,7 @@ async def make_query_image(user_info: UserInfoSuccess, game_data: GameData, even
|
||||
user=People(
|
||||
avatar=await get_avatar(event_user_info, 'Data URI', None)
|
||||
if event_user_info is not None
|
||||
else get_random_avatar(),
|
||||
else get_random_avatar(user_info.data.teaid),
|
||||
name=user_info.data.name,
|
||||
),
|
||||
ranking=Ranking(rating=float(user_info.data.ranking), rd=round(float(user_info.data.rd_now), 2)),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from base64 import b64encode
|
||||
from io import BytesIO
|
||||
from random import choice, randint
|
||||
from random import Random
|
||||
|
||||
from PIL import Image
|
||||
from PIL.Image import Resampling
|
||||
@@ -8,12 +8,13 @@ from PIL.Image import Resampling
|
||||
from .draw import PIECE_MEMBERS, SkinManager
|
||||
|
||||
|
||||
def get_avatar() -> str:
|
||||
def get_avatar(send: float | str | bytes | bytearray | None = None) -> str:
|
||||
random = Random(send) # noqa: S311
|
||||
skin = (
|
||||
SkinManager.get_skin()
|
||||
.get_piece(choice(PIECE_MEMBERS)) # noqa: S311
|
||||
SkinManager.get_skin(send)
|
||||
.get_piece(random.choice(PIECE_MEMBERS))
|
||||
.rotate(
|
||||
randint(-360, 360), # noqa: S311
|
||||
random.randint(-360, 360),
|
||||
expand=True,
|
||||
resample=Resampling.BICUBIC,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from enum import Enum
|
||||
from random import choice
|
||||
from random import Random
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from PIL.Image import Image
|
||||
@@ -151,8 +151,8 @@ class SkinManager:
|
||||
cls.skin.append(skin)
|
||||
|
||||
@classmethod
|
||||
def get_skin(cls) -> 'Skin':
|
||||
return choice(cls.skin) # noqa: S311
|
||||
def get_skin(cls, send: float | str | bytes | bytearray | None = None) -> 'Skin':
|
||||
return Random(send).choice(cls.skin) # noqa: S311
|
||||
|
||||
|
||||
class Skin(ABC):
|
||||
|
||||
@@ -90,5 +90,5 @@ class TechSkin(Skin):
|
||||
@driver.on_startup
|
||||
def _():
|
||||
path = Path(__file__).parent / 'skins'
|
||||
for i in path.iterdir():
|
||||
for i in sorted(path.iterdir()):
|
||||
TechSkin(i)
|
||||
|
||||
Reference in New Issue
Block a user