From 86198df4ed326ecc810310836c9ccb7116b38465 Mon Sep 17 00:00:00 2001 From: shoucandanghehe Date: Tue, 15 Apr 2025 03:30:30 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E9=80=82=E9=85=8D=20bind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_tetris_stats/games/tetrio/bind.py | 6 ++++-- nonebot_plugin_tetris_stats/games/tetrio/unbind.py | 6 ++++-- nonebot_plugin_tetris_stats/games/top/bind.py | 6 ++++-- nonebot_plugin_tetris_stats/games/top/unbind.py | 6 ++++-- nonebot_plugin_tetris_stats/games/tos/bind.py | 6 ++++-- nonebot_plugin_tetris_stats/games/tos/unbind.py | 6 ++++-- nonebot_plugin_tetris_stats/utils/lang.py | 8 ++++++++ nonebot_plugin_tetris_stats/utils/render/schemas/base.py | 4 ++-- nonebot_plugin_tetris_stats/utils/typedefs.py | 2 ++ 9 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 nonebot_plugin_tetris_stats/utils/lang.py diff --git a/nonebot_plugin_tetris_stats/games/tetrio/bind.py b/nonebot_plugin_tetris_stats/games/tetrio/bind.py index f4ee319..d1f7f4d 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/bind.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/bind.py @@ -13,6 +13,7 @@ from yarl import URL from ...db import BindStatus, create_or_update_bind, trigger from ...utils.host import HostPage, get_self_netloc from ...utils.image import get_avatar +from ...utils.lang import get_lang from ...utils.render import Bind, render from ...utils.render.schemas.base import Avatar, People from ...utils.screenshot import screenshot @@ -65,7 +66,7 @@ async def _(nb_user: User, account: Player, event_session: EventSession, bot_inf 'v1/binding', Bind( platform='TETR.IO', - status='unknown', + type='unknown', user=People( avatar=str( URL(f'http://{netloc}/host/resource/tetrio/avatars/{user.ID}') @@ -79,7 +80,8 @@ async def _(nb_user: User, account: Player, event_session: EventSession, bot_inf avatar=await get_avatar(bot_info, 'Data URI', '../../static/logo/logo.svg'), name=bot_info.user_name, ), - command='io查我', + prompt='io查我', + _lang=get_lang(), ), ) ) as page_hash: diff --git a/nonebot_plugin_tetris_stats/games/tetrio/unbind.py b/nonebot_plugin_tetris_stats/games/tetrio/unbind.py index c03cdb0..457620d 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/unbind.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/unbind.py @@ -13,6 +13,7 @@ from yarl import URL from ...db import query_bind_info, remove_bind, trigger from ...utils.host import HostPage, get_self_netloc from ...utils.image import get_avatar +from ...utils.lang import get_lang from ...utils.render import Bind, render from ...utils.render.schemas.base import Avatar, People from ...utils.screenshot import screenshot @@ -53,7 +54,7 @@ async def _(nb_user: User, event_session: EventSession, bot_info: UserInfo = Bot 'v1/binding', Bind( platform='TETR.IO', - status='unlink', + type='unlink', user=People( avatar=str( URL(f'http://{netloc}/host/resource/tetrio/avatars/{user.ID}') @@ -67,7 +68,8 @@ async def _(nb_user: User, event_session: EventSession, bot_info: UserInfo = Bot avatar=await get_avatar(bot_info, 'Data URI', '../../static/logo/logo.svg'), name=bot_info.user_name, ), - command='io绑定{游戏ID}', + prompt='io绑定{游戏ID}', + _lang=get_lang(), ), ) ) as page_hash: diff --git a/nonebot_plugin_tetris_stats/games/top/bind.py b/nonebot_plugin_tetris_stats/games/top/bind.py index d453f7d..8cb8d1d 100644 --- a/nonebot_plugin_tetris_stats/games/top/bind.py +++ b/nonebot_plugin_tetris_stats/games/top/bind.py @@ -8,6 +8,7 @@ from nonebot_plugin_userinfo import BotUserInfo, EventUserInfo, UserInfo from ...db import BindStatus, create_or_update_bind, trigger from ...utils.host import HostPage, get_self_netloc from ...utils.image import get_avatar +from ...utils.lang import get_lang from ...utils.render import Bind, render from ...utils.render.schemas.base import People from ...utils.screenshot import screenshot @@ -44,7 +45,7 @@ async def _( 'v1/binding', Bind( platform=GAME_TYPE, - status='unknown', + type='unknown', user=People( avatar=await get_avatar(event_user_info, 'Data URI', None), name=user.user_name, @@ -53,7 +54,8 @@ async def _( avatar=await get_avatar(bot_info, 'Data URI', '../../static/logo/logo.svg'), name=bot_info.user_name, ), - command='top查我', + prompt='top查我', + _lang=get_lang(), ), ) ) as page_hash: diff --git a/nonebot_plugin_tetris_stats/games/top/unbind.py b/nonebot_plugin_tetris_stats/games/top/unbind.py index 01b8b09..dc84558 100644 --- a/nonebot_plugin_tetris_stats/games/top/unbind.py +++ b/nonebot_plugin_tetris_stats/games/top/unbind.py @@ -9,6 +9,7 @@ from nonebot_plugin_waiter import suggest # type: ignore[import-untyped] from ...db import query_bind_info, remove_bind, trigger from ...utils.host import HostPage, get_self_netloc from ...utils.image import get_avatar +from ...utils.lang import get_lang from ...utils.render import Bind, render from ...utils.render.schemas.base import People from ...utils.screenshot import screenshot @@ -46,7 +47,7 @@ async def _( 'v1/binding', Bind( platform='TOP', - status='unlink', + type='unlink', user=People( avatar=await get_avatar(event_user_info, 'Data URI', None), name=user.user_name, @@ -55,7 +56,8 @@ async def _( avatar=await get_avatar(bot_info, 'Data URI', '../../static/logo/logo.svg'), name=bot_info.user_name, ), - command='top绑定{游戏ID}', + prompt='top绑定{游戏ID}', + _lang=get_lang(), ), ) ) as page_hash: diff --git a/nonebot_plugin_tetris_stats/games/tos/bind.py b/nonebot_plugin_tetris_stats/games/tos/bind.py index 9694484..798bc0d 100644 --- a/nonebot_plugin_tetris_stats/games/tos/bind.py +++ b/nonebot_plugin_tetris_stats/games/tos/bind.py @@ -8,6 +8,7 @@ from nonebot_plugin_userinfo import BotUserInfo, EventUserInfo, UserInfo from ...db import BindStatus, create_or_update_bind, trigger from ...utils.host import HostPage, get_self_netloc from ...utils.image import get_avatar +from ...utils.lang import get_lang from ...utils.render import Bind, render from ...utils.render.schemas.base import People from ...utils.screenshot import screenshot @@ -45,7 +46,7 @@ async def _( 'v1/binding', Bind( platform=GAME_TYPE, - status='unknown', + type='unknown', user=People( avatar=await get_avatar(event_user_info, 'Data URI', None), name=user_info.data.name ), @@ -53,7 +54,8 @@ async def _( avatar=await get_avatar(bot_info, 'Data URI', '../../static/logo/logo.svg'), name=bot_info.user_remark or bot_info.user_displayname or bot_info.user_name, ), - command='茶服查我', + prompt='茶服查我', + _lang=get_lang(), ), ) ) as page_hash: diff --git a/nonebot_plugin_tetris_stats/games/tos/unbind.py b/nonebot_plugin_tetris_stats/games/tos/unbind.py index 8c34e81..68f89ed 100644 --- a/nonebot_plugin_tetris_stats/games/tos/unbind.py +++ b/nonebot_plugin_tetris_stats/games/tos/unbind.py @@ -9,6 +9,7 @@ from nonebot_plugin_waiter import suggest # type: ignore[import-untyped] from ...db import query_bind_info, remove_bind, trigger from ...utils.host import HostPage, get_self_netloc from ...utils.image import get_avatar +from ...utils.lang import get_lang from ...utils.render import Bind, render from ...utils.render.avatar import get_avatar as get_random_avatar from ...utils.render.schemas.base import People @@ -47,7 +48,7 @@ async def _( 'v1/binding', Bind( platform='TOS', - status='unlink', + type='unlink', user=People( avatar=await get_avatar(event_user_info, 'Data URI', None) if event_user_info is not None @@ -58,7 +59,8 @@ async def _( avatar=await get_avatar(bot_info, 'Data URI', '../../static/logo/logo.svg'), name=bot_info.user_name, ), - command='茶服绑定{游戏ID}', + prompt='茶服绑定{游戏ID}', + _lang=get_lang(), ), ) ) as page_hash: diff --git a/nonebot_plugin_tetris_stats/utils/lang.py b/nonebot_plugin_tetris_stats/utils/lang.py new file mode 100644 index 0000000..3f2640d --- /dev/null +++ b/nonebot_plugin_tetris_stats/utils/lang.py @@ -0,0 +1,8 @@ +from typing import cast + +from ..i18n.model import Lang +from .typedefs import Lang as LangType + + +def get_lang() -> LangType: + return cast('LangType', Lang.template.template_language()) diff --git a/nonebot_plugin_tetris_stats/utils/render/schemas/base.py b/nonebot_plugin_tetris_stats/utils/render/schemas/base.py index 95e512e..ec63dd1 100644 --- a/nonebot_plugin_tetris_stats/utils/render/schemas/base.py +++ b/nonebot_plugin_tetris_stats/utils/render/schemas/base.py @@ -4,11 +4,11 @@ from typing import Literal from pydantic import BaseModel from strenum import StrEnum -from ...typedefs import Number +from ...typedefs import Lang, Number class Base(BaseModel): - _lang: Literal['zh-CN', 'en-US'] + _lang: Lang class Avatar(BaseModel): diff --git a/nonebot_plugin_tetris_stats/utils/typedefs.py b/nonebot_plugin_tetris_stats/utils/typedefs.py index 7edb3ae..60d4903 100644 --- a/nonebot_plugin_tetris_stats/utils/typedefs.py +++ b/nonebot_plugin_tetris_stats/utils/typedefs.py @@ -59,3 +59,5 @@ Me: TypeAlias = Literal[ 'self', 'oneself', ] + +Lang: TypeAlias = Literal['zh-CN', 'en-US']