From 9a00d3d73191e7fc27b6a03a2d4112b4ba5df8eb Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Tue, 7 Apr 2026 20:29:43 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=AE=8C=E5=96=84=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E8=B5=9B=E9=A9=AC=E6=B5=8B=E8=AF=95=E4=B8=AD=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=9C=8D=E5=8A=A1=E6=A8=A1=E6=8B=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 _NoopMessageService 添加基本消息记录和撤回功能,以支持 race_update 消息的防刷屏机制。这使得测试环境能更真实地模拟生产代码的行为,确保在模拟密集更新时不会因消息过多而影响测试观察。 --- .../group_horse_racing/test_commands.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/danding_bot/plugins/group_horse_racing/test_commands.py b/danding_bot/plugins/group_horse_racing/test_commands.py index 7d22724..fd20c9d 100644 --- a/danding_bot/plugins/group_horse_racing/test_commands.py +++ b/danding_bot/plugins/group_horse_racing/test_commands.py @@ -196,14 +196,42 @@ class _InMemoryPointsService: class _NoopMessageService: + def __init__(self): + self.last_messages: dict[str, dict[str, str]] = {} + def clear_pending_recalls(self, scope: str): - return + if scope in self.last_messages: + del self.last_messages[scope] async def send_with_recall(self, bot, scope, message_type, message): + # Support basic recall for race_update to avoid flooding during simulation + if message_type == "race_update": + await self.recall_previous_of_type(bot, scope, "race_update") + + is_group = scope.startswith("group_") + result = await bot.send_msg( + message_type="group" if is_group else "private", + group_id=int(scope.split("_", 1)[1]) if is_group else None, + user_id=int(scope.split("_", 1)[1]) if not is_group else None, + message=message, + ) + + if scope not in self.last_messages: + self.last_messages[scope] = {} + + if isinstance(result, dict) and "message_id" in result: + self.last_messages[scope][message_type] = result["message_id"] + return "fake_msg_id" async def recall_previous_of_type(self, bot, scope, message_type): - return + if scope in self.last_messages and message_type in self.last_messages[scope]: + msg_id = self.last_messages[scope][message_type] + try: + await bot.delete_msg(message_id=msg_id) + except Exception: + pass + del self.last_messages[scope][message_type] @test_simulate_race_cmd.handle()