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()