diff --git a/nonebot_plugin_tetris_stats/game_data_processor/__init__.py b/nonebot_plugin_tetris_stats/game_data_processor/__init__.py index b34ec9f..ab8bd46 100644 --- a/nonebot_plugin_tetris_stats/game_data_processor/__init__.py +++ b/nonebot_plugin_tetris_stats/game_data_processor/__init__.py @@ -55,7 +55,7 @@ class Processor(ABC): raise NotImplementedError @abstractmethod - async def handle_query(self) -> str: + async def handle_query(self) -> UniMessage: """处理查询消息""" raise NotImplementedError diff --git a/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/__init__.py b/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/__init__.py index 8a801cc..a924cc0 100644 --- a/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/__init__.py +++ b/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/__init__.py @@ -5,6 +5,7 @@ from arclet.alconna import Alconna, AllParam, Arg, ArgFlag, Args, CommandMeta, O from nonebot.adapters import Bot, Event from nonebot.matcher import Matcher from nonebot_plugin_alconna import At, on_alconna +from nonebot_plugin_alconna.uniseg import UniMessage from nonebot_plugin_orm import get_session from nonebot_plugin_userinfo import BotUserInfo, UserInfo # type: ignore[import-untyped] from sqlalchemy import func, select @@ -117,10 +118,11 @@ async def _(bot: Bot, event: Event, matcher: Matcher, target: At | Me): command_args=[], ) try: - await matcher.finish(message + await proc.handle_query()) + await (UniMessage(message) + await proc.handle_query()).send() except NeedCatchError as e: await matcher.send(str(e)) raise HandleNotFinishedError from e + await matcher.finish() @alc.assign('query') @@ -131,10 +133,11 @@ async def _(event: Event, matcher: Matcher, account: User): command_args=[], ) try: - await matcher.finish(await proc.handle_query()) + await (await proc.handle_query()).send() except NeedCatchError as e: await matcher.send(str(e)) raise HandleNotFinishedError from e + await matcher.finish() @alc.assign('rank') diff --git a/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/processor.py b/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/processor.py index b4c421e..51c2423 100644 --- a/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/processor.py +++ b/nonebot_plugin_tetris_stats/game_data_processor/io_data_processor/processor.py @@ -115,7 +115,7 @@ class Processor(ProcessorMeta): return message @override - async def handle_query(self) -> str: + async def handle_query(self) -> UniMessage: """处理查询消息""" self.command_type = 'query' await self.get_user() @@ -156,7 +156,7 @@ class Processor(ProcessorMeta): raise WhatTheFuckError('Blitz记录不是单人记录') ret_message += f'\nBlitz: {blitz.record.endcontext.score}' ret_message += f' ( #{blitz.rank} )' if blitz.rank is not None else '' - return ret_message + return UniMessage(ret_message) async def get_user(self) -> None: """ diff --git a/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/__init__.py b/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/__init__.py index 8b15483..457f974 100644 --- a/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/__init__.py +++ b/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/__init__.py @@ -2,6 +2,7 @@ from arclet.alconna import Alconna, AllParam, Arg, ArgFlag, Args, CommandMeta, O from nonebot.adapters import Bot, Event from nonebot.matcher import Matcher from nonebot_plugin_alconna import At, on_alconna +from nonebot_plugin_alconna.uniseg import UniMessage from nonebot_plugin_orm import get_session from nonebot_plugin_userinfo import BotUserInfo, EventUserInfo, UserInfo # type: ignore[import-untyped] @@ -111,10 +112,11 @@ async def _(bot: Bot, event: Event, matcher: Matcher, target: At | Me): command_args=[], ) try: - await matcher.finish(message + await proc.handle_query()) + await (UniMessage(message) + await proc.handle_query()).send() except NeedCatchError as e: await matcher.send(str(e)) raise HandleNotFinishedError from e + await matcher.finish() @alc.assign('query') @@ -125,10 +127,11 @@ async def _(event: Event, matcher: Matcher, account: User): command_args=[], ) try: - await matcher.finish(await proc.handle_query()) + await (await proc.handle_query()).send() except NeedCatchError as e: await matcher.send(str(e)) raise HandleNotFinishedError from e + await matcher.finish() add_default_handlers(alc) diff --git a/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/processor.py b/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/processor.py index c022aed..5a82790 100644 --- a/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/processor.py +++ b/nonebot_plugin_tetris_stats/game_data_processor/top_data_processor/processor.py @@ -105,7 +105,7 @@ class Processor(ProcessorMeta): return message @override - async def handle_query(self) -> str: + async def handle_query(self) -> UniMessage: """处理查询消息""" self.command_type = 'query' await self.check_user() @@ -123,7 +123,7 @@ class Processor(ProcessorMeta): message += f'\nAPM: {round(game_data.total.apm,2)} ( x{round(game_data.total.apm/game_data.total.lpm,2)} )' else: message += '\n暂无历史统计数据' - return message + return UniMessage(message) async def get_user_profile(self) -> str: """获取用户信息""" diff --git a/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/__init__.py b/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/__init__.py index fcc8677..9c92161 100644 --- a/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/__init__.py +++ b/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/__init__.py @@ -4,6 +4,7 @@ from arclet.alconna import Alconna, AllParam, Arg, ArgFlag, Args, CommandMeta, O from nonebot.adapters import Bot, Event from nonebot.matcher import Matcher from nonebot_plugin_alconna import At, on_alconna +from nonebot_plugin_alconna.uniseg import UniMessage from nonebot_plugin_orm import get_session from nonebot_plugin_userinfo import BotUserInfo, UserInfo # type: ignore[import-untyped] @@ -72,12 +73,13 @@ alc = on_alconna( async def finish_special_query(matcher: Matcher, proc: Processor) -> NoReturn: try: - await matcher.finish(await proc.handle_query()) + await (await proc.handle_query()).send() except NeedCatchError as e: if isinstance(e, RequestError) and '未找到此用户' in e.message: matcher.skip() await matcher.send(str(e)) raise HandleNotFinishedError from e + await matcher.finish() try: @@ -165,10 +167,11 @@ async def _(bot: Bot, event: Event, matcher: Matcher, target: At | Me): command_args=[], ) try: - await matcher.finish(message + await proc.handle_query()) + await (UniMessage(message) + await proc.handle_query()).send() except NeedCatchError as e: await matcher.send(str(e)) raise HandleNotFinishedError from e + await matcher.finish() @alc.assign('query') @@ -179,10 +182,11 @@ async def _(event: Event, matcher: Matcher, account: User): command_args=[], ) try: - await matcher.finish(await proc.handle_query()) + await (await proc.handle_query()).send() except NeedCatchError as e: await matcher.send(str(e)) raise HandleNotFinishedError from e + await matcher.finish() add_default_handlers(alc) diff --git a/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/processor.py b/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/processor.py index 00e7043..974b223 100644 --- a/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/processor.py +++ b/nonebot_plugin_tetris_stats/game_data_processor/tos_data_processor/processor.py @@ -119,7 +119,7 @@ class Processor(ProcessorMeta): return message @override - async def handle_query(self) -> str: + async def handle_query(self) -> UniMessage: """处理查询消息""" self.command_type = 'query' await self.get_user() @@ -140,7 +140,7 @@ class Processor(ProcessorMeta): message += f'\n40L: {float(user_info.pb_sprint)/1000:.2f}s' if user_info.pb_sprint != '2147483647' else '' message += f'\nMarathon: {user_info.pb_marathon}' if user_info.pb_marathon != '0' else '' message += f'\nChallenge: {user_info.pb_challenge}' if user_info.pb_challenge != '0' else '' - return message + return UniMessage(message) async def get_user(self) -> None: """