mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
👽️ 适配 茶服 新赛季 (#216)
* 👽️ 适配 茶服 新赛季 * ✏️ 少个- * ➕ 添加开发依赖 nonebot-adapter-kaiheila * ✨ 适配 kook 茶服查target * 🐛 修复 onebotv11 查自己 找不到用户的bug * 🐛 修复 茶服 查绑定 找不到用户的bug * ✨ kook 茶服查target 添加后备方案 * ➕ 添加开发依赖 nonebot-adapter-discord * ✨ 适配 discord 茶服查target
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Del old TOS bind data
|
||||
|
||||
迁移 ID: b9d65badc713
|
||||
父迁移: 6c3206f90cc3
|
||||
创建时间: 2023-12-30 00:27:40.991704
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
revision: str = 'b9d65badc713'
|
||||
down_revision: str | Sequence[str] | None = '6c3206f90cc3'
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade(name: str = '') -> None:
|
||||
if name:
|
||||
return
|
||||
|
||||
Base = automap_base() # noqa: N806
|
||||
connection = op.get_bind()
|
||||
Base.prepare(autoload_with=connection)
|
||||
|
||||
Bind = Base.classes.nonebot_plugin_tetris_stats_bind # noqa: N806
|
||||
with Session(connection) as session:
|
||||
session.query(Bind).filter(Bind.game_platform == 'TOS').delete()
|
||||
session.commit()
|
||||
|
||||
|
||||
def downgrade(name: str = '') -> None:
|
||||
if name:
|
||||
return
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import NoReturn
|
||||
|
||||
from arclet.alconna import Alconna, AllParam, Arg, ArgFlag, Args, CommandMeta, Option
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.matcher import Matcher
|
||||
@@ -5,7 +7,7 @@ from nonebot_plugin_alconna import At, on_alconna
|
||||
from nonebot_plugin_orm import get_session
|
||||
|
||||
from ...db import query_bind_info
|
||||
from ...utils.exception import HandleNotFinishedError, NeedCatchError
|
||||
from ...utils.exception import HandleNotFinishedError, NeedCatchError, RequestError
|
||||
from ...utils.platform import get_platform
|
||||
from ...utils.typing import Me
|
||||
from .. import add_default_handlers
|
||||
@@ -66,28 +68,60 @@ alc = on_alconna(
|
||||
aliases={'tos', 'TOS'},
|
||||
)
|
||||
|
||||
try:
|
||||
from nonebot.adapters.onebot.v11 import GROUP, MessageEvent
|
||||
from nonebot.adapters.onebot.v11 import Bot as OB11Bot
|
||||
|
||||
@alc.assign('bind')
|
||||
async def _(event: MessageEvent, matcher: Matcher):
|
||||
await matcher.finish('QQ 平台无需绑定')
|
||||
async def finish_special_query(matcher: Matcher, proc: Processor) -> NoReturn:
|
||||
try:
|
||||
await matcher.finish(await proc.handle_query())
|
||||
except NeedCatchError as e:
|
||||
if isinstance(e, RequestError) and '未找到此用户' in e.message:
|
||||
matcher.skip()
|
||||
await matcher.send(str(e))
|
||||
raise HandleNotFinishedError from e
|
||||
|
||||
|
||||
try:
|
||||
from nonebot.adapters.onebot.v11 import GROUP as OB11GROUP
|
||||
from nonebot.adapters.onebot.v11 import Bot as OB11Bot
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent as OB11MessageEvent
|
||||
|
||||
@alc.assign('query')
|
||||
async def _(bot: OB11Bot, event: MessageEvent, matcher: Matcher, target: At | Me):
|
||||
if event.is_tome() and await GROUP(bot, event):
|
||||
async def _(bot: OB11Bot, event: OB11MessageEvent, matcher: Matcher, target: At | Me):
|
||||
if event.is_tome() and await OB11GROUP(bot, event):
|
||||
await matcher.finish('不能查询bot的信息')
|
||||
proc = Processor(
|
||||
event_id=id(event),
|
||||
user=User(teaid=target.target if isinstance(target, At) else event.get_user_id()),
|
||||
user=User(teaid=f'onebot-{target.target}' if isinstance(target, At) else f'onebot-{event.get_user_id()}'),
|
||||
command_args=[],
|
||||
)
|
||||
try:
|
||||
await matcher.send(await proc.handle_query())
|
||||
except NeedCatchError as e:
|
||||
await matcher.send(str(e))
|
||||
raise HandleNotFinishedError from e
|
||||
await finish_special_query(matcher, proc)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from nonebot.adapters.kaiheila.event import MessageEvent as KookMessageEvent
|
||||
|
||||
@alc.assign('query')
|
||||
async def _(event: KookMessageEvent, matcher: Matcher, target: At | Me):
|
||||
proc = Processor(
|
||||
event_id=id(event),
|
||||
user=User(teaid=f'kook-{target.target}' if isinstance(target, At) else f'kook-{event.get_user_id()}'),
|
||||
command_args=[],
|
||||
)
|
||||
await finish_special_query(matcher, proc)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from nonebot.adapters.discord import MessageEvent as DiscordMessageEvent
|
||||
|
||||
@alc.assign('query')
|
||||
async def _(event: DiscordMessageEvent, matcher: Matcher, target: At | Me):
|
||||
proc = Processor(
|
||||
event_id=id(event),
|
||||
user=User(teaid=f'discord-{target.target}' if isinstance(target, At) else f'discord-{event.get_user_id()}'),
|
||||
command_args=[],
|
||||
)
|
||||
await finish_special_query(matcher, proc)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@@ -120,7 +154,7 @@ async def _(bot: Bot, event: Event, matcher: Matcher, target: At | Me):
|
||||
message = '* 由于无法验证绑定信息, 不能保证查询到的用户为本人\n'
|
||||
proc = Processor(
|
||||
event_id=id(event),
|
||||
user=User(name=bind.game_account),
|
||||
user=User(teaid=bind.game_account),
|
||||
command_args=[],
|
||||
)
|
||||
try:
|
||||
|
||||
@@ -53,7 +53,7 @@ def identify_user_info(info: str) -> User | MessageFormatError:
|
||||
and 2 <= len(info) <= 18 # noqa: PLR2004
|
||||
):
|
||||
return User(name=info)
|
||||
if info.isdigit():
|
||||
if info.startswith(('onebot-', 'qqguild-', 'kook-', 'discord-')) and info.split('-', maxsplit=1)[1].isdigit():
|
||||
return User(teaid=info)
|
||||
return MessageFormatError('用户名/QQ号不合法')
|
||||
|
||||
@@ -76,15 +76,13 @@ class Processor(ProcessorMeta):
|
||||
"""处理绑定消息"""
|
||||
self.command_type = 'bind'
|
||||
await self.get_user()
|
||||
if self.user.name is None:
|
||||
raise # FIXME: 不知道怎么才能把这类型给变过来了
|
||||
async with get_session() as session:
|
||||
return await create_or_update_bind(
|
||||
session=session,
|
||||
chat_platform=platform,
|
||||
chat_account=account,
|
||||
game_platform=GAME_TYPE,
|
||||
game_account=self.user.name,
|
||||
game_account=self.user.unique_identifier,
|
||||
)
|
||||
|
||||
async def handle_query(self) -> str:
|
||||
|
||||
45
poetry.lock
generated
45
poetry.lock
generated
@@ -112,13 +112,13 @@ zookeeper = ["kazoo"]
|
||||
|
||||
[[package]]
|
||||
name = "arclet-alconna"
|
||||
version = "1.7.32"
|
||||
version = "1.7.41"
|
||||
description = "A High-performance, Generality, Humane Command Line Arguments Parser Library."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "arclet_alconna-1.7.32-py3-none-any.whl", hash = "sha256:25d7c19112a18a54688191b9ff95cfdf4c852b1340121719acba836c464d6280"},
|
||||
{file = "arclet_alconna-1.7.32.tar.gz", hash = "sha256:7fb3424affe3085804b949b571a4119c5a5ecc29f79db31821801cd0d16c9b7a"},
|
||||
{file = "arclet_alconna-1.7.41-py3-none-any.whl", hash = "sha256:2e929cc45183d052c818a1bfb8fe79d4c534b1ef42bd4a3dd8e13792d3f22e02"},
|
||||
{file = "arclet_alconna-1.7.41.tar.gz", hash = "sha256:76bd862a91a205f51d90506ab67218cee4876de8fdcffade1c4b8fee9740cd2c"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -862,6 +862,35 @@ files = [
|
||||
tarina = ">=0.3.3"
|
||||
typing-extensions = ">=4.5.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-adapter-discord"
|
||||
version = "0.1.2"
|
||||
description = "Discord adapter for nonebot2"
|
||||
optional = false
|
||||
python-versions = ">=3.8,<4.0"
|
||||
files = [
|
||||
{file = "nonebot_adapter_discord-0.1.2-py3-none-any.whl", hash = "sha256:2495c2e4678206e3e609afd5ed91bd45679f7e7b6e53d6084d3b23fc76e63a4d"},
|
||||
{file = "nonebot_adapter_discord-0.1.2.tar.gz", hash = "sha256:88cadc1aefe7a479f1f916e002689cf496ad986f3bb6fd32d98a34f9b3632a8c"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
nonebot2 = ">=2.0.0,<3.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-adapter-kaiheila"
|
||||
version = "0.3.0"
|
||||
description = "kaiheila adapter for nonebot2"
|
||||
optional = false
|
||||
python-versions = ">=3.8,<4.0"
|
||||
files = [
|
||||
{file = "nonebot_adapter_kaiheila-0.3.0-py3-none-any.whl", hash = "sha256:8868f57f9ac591dff46d5cf711c419aa76ece22a5dd2380abc33d337132b5157"},
|
||||
{file = "nonebot_adapter_kaiheila-0.3.0.tar.gz", hash = "sha256:b32b4e9d911b98ae0270540ed7fa414e94f74b228363b6b012ae2f2d54ed4e21"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
nonebot2 = ">=2.0.0,<3.0.0"
|
||||
typing-extensions = ">=4.8.0,<5.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-adapter-onebot"
|
||||
version = "2.3.1"
|
||||
@@ -894,17 +923,17 @@ nonebot2 = ">=2.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-plugin-alconna"
|
||||
version = "0.33.6"
|
||||
version = "0.34.1"
|
||||
description = "Alconna Adapter for Nonebot"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "nonebot_plugin_alconna-0.33.6-py3-none-any.whl", hash = "sha256:89989dd6dc1bccd8a1603159b57e9e96da438eb0bbbdbbcd2bfcf747594e12c3"},
|
||||
{file = "nonebot_plugin_alconna-0.33.6.tar.gz", hash = "sha256:54e761ef621c8285cd9ea2f81324f9f52f6fb6292d3ddb87387dbdcaeaa8dc1b"},
|
||||
{file = "nonebot_plugin_alconna-0.34.1-py3-none-any.whl", hash = "sha256:c8e71ffad194e30f14ae7a53e29483b2a59328df2fc8d4ba9e1c407f2f76bf0d"},
|
||||
{file = "nonebot_plugin_alconna-0.34.1.tar.gz", hash = "sha256:12a8809bd3ee96ecaa25b20ad3950f7078eb1d109ad2f6656c581ddcdb3244d6"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
arclet-alconna = ">=1.7.31,<2.0.0"
|
||||
arclet-alconna = ">=1.7.38,<2.0.0"
|
||||
arclet-alconna-tools = ">=0.6.7,<0.7.0"
|
||||
fleep = ">=1.0.1"
|
||||
nepattern = ">=0.5.14,<0.6.0"
|
||||
@@ -2124,4 +2153,4 @@ multidict = ">=4.0"
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "e523f1239c9c0373499c2ee7a9c04a7400334ea94bec5105a8497bdb7da29f98"
|
||||
content-hash = "2107a0af7834f17c5091eb88dcb0f4d30cf571f6e4fe0beabaaac7f4ddb78d87"
|
||||
|
||||
@@ -19,7 +19,7 @@ aiofiles = "^23.2.1"
|
||||
nonebot-plugin-orm = ">=0.1.1,<0.7.0"
|
||||
nonebot-plugin-localstore = "^0.5.1"
|
||||
httpx = "^0.25.0"
|
||||
nonebot-plugin-alconna = ">=0.30,<0.34"
|
||||
nonebot-plugin-alconna = ">=0.30,<0.35"
|
||||
nonebot-plugin-apscheduler = "^0.3.0"
|
||||
aiocache = "^0.12.2"
|
||||
|
||||
@@ -34,6 +34,8 @@ types-lxml = "^2023.3.28"
|
||||
nonebot-plugin-orm = { extras = ["default"], version = ">=0.3,<0.7" }
|
||||
nonebot-adapter-onebot = "^2.3.1"
|
||||
nonebot-adapter-satori = "^0.8.0"
|
||||
nonebot-adapter-kaiheila = "^0.3.0"
|
||||
nonebot-adapter-discord = "^0.1.2"
|
||||
|
||||
[tool.poetry.group.debug.dependencies]
|
||||
objprint = '^0.2.2'
|
||||
|
||||
Reference in New Issue
Block a user