Files
nonebot-plugin-tetris-stats/nonebot_plugin_tetris_stats/games/tos/__init__.py
pre-commit-ci[bot] bb8943d4c3
Some checks failed
Code Coverage / Test (macos-latest, 3.10) (push) Waiting to run
Code Coverage / Test (macos-latest, 3.11) (push) Waiting to run
Code Coverage / Test (macos-latest, 3.12) (push) Waiting to run
Code Coverage / Test (ubuntu-latest, 3.10) (push) Waiting to run
Code Coverage / Test (ubuntu-latest, 3.11) (push) Waiting to run
Code Coverage / Test (ubuntu-latest, 3.12) (push) Waiting to run
Code Coverage / Test (windows-latest, 3.10) (push) Waiting to run
Code Coverage / Test (windows-latest, 3.11) (push) Waiting to run
Code Coverage / Test (windows-latest, 3.12) (push) Waiting to run
Code Coverage / check (push) Blocked by required conditions
TypeCheck / TypeCheck (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
⬆️ auto update by pre-commit hooks (#529)
* ⬆️ auto update by pre-commit hooks

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.3 → v0.9.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.3...v0.9.6)

* 🚨 auto fix by pre-commit hooks

* ♻️ 重命名 typing 为 typedefs

* ♻️ 使用 Annotated 代替默认值

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: shoucandanghehe <wallfjjd@gmail.com>
2025-02-13 04:18:36 +08:00

82 lines
2.3 KiB
Python

from arclet.alconna import Arg, ArgFlag
from nonebot_plugin_alconna import Args, At, Subcommand
from ...utils.exception import MessageFormatError
from ...utils.typedefs import Me
from .. import add_block_handlers, alc, command
from .api import Player
from .constant import USER_NAME
def get_player(teaid_or_name: str) -> Player | MessageFormatError:
if (
teaid_or_name.startswith(('onebot-', 'qqguild-', 'kook-', 'discord-'))
and teaid_or_name.split('-', maxsplit=1)[1].isdigit()
):
return Player(teaid=teaid_or_name, trust=True)
if USER_NAME.match(teaid_or_name) and not teaid_or_name.isdigit() and 2 <= len(teaid_or_name) <= 18: # noqa: PLR2004
return Player(user_name=teaid_or_name, trust=True)
return MessageFormatError('用户名/ID不合法')
command.add(
Subcommand(
'TOS',
Subcommand(
'bind',
Args(
Arg(
'account',
get_player,
notice='茶服 用户名 / ID',
flags=[ArgFlag.HIDDEN],
)
),
help_text='绑定 茶服 账号',
),
Subcommand(
'unbind',
help_text='解除绑定 TOS 账号',
),
Subcommand(
'query',
Args(
Arg(
'target',
At | Me,
notice='@想要查询的人 / 自己',
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
),
Arg(
'account',
get_player,
notice='茶服 用户名 / TeaID',
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
),
),
help_text='查询 茶服 游戏信息',
),
help_text='茶服 游戏相关指令',
)
)
alc.shortcut(
'(?i:tos|茶服)(?i:绑定|绑|bind)',
command='tstats TOS bind',
humanized='茶服绑定',
)
alc.shortcut(
'(?i:tos|茶服)(?i:解除绑定|解绑|unbind)',
command='tstats TOS unbind',
humanized='茶服解绑',
)
alc.shortcut(
'(?i:tos|茶服)(?i:查询|查|query|stats)',
command='tstats TOS query',
humanized='茶服查',
)
add_block_handlers(alc.assign('TOS.query'))
from . import bind, query, unbind # noqa: E402, F401