diff --git a/danding_bot/plugins/group_horse_racing/test_commands.py b/danding_bot/plugins/group_horse_racing/test_commands.py index dea227a..efaddb3 100644 --- a/danding_bot/plugins/group_horse_racing/test_commands.py +++ b/danding_bot/plugins/group_horse_racing/test_commands.py @@ -214,6 +214,7 @@ async def handle_test_simulate_race(bot: Bot, event: Event): original_points_service = commands_mod.points_service original_message_service = commands_mod.message_service original_tick_interval = commands_mod.config.RACE_TICK_INTERVAL + original_stop_race = commands_mod.race_engine.stop_race fake_room_store = _InMemoryRoomStore() @@ -230,6 +231,7 @@ async def handle_test_simulate_race(bot: Bot, event: Event): commands_mod.points_service = fake_points_service commands_mod.message_service = fake_message_service commands_mod.config.RACE_TICK_INTERVAL = 0 + commands_mod.race_engine.stop_race = lambda _scope: commands_mod.race_engine.active_tasks.pop(_scope, None) room = fake_room_store.create_room(scope) horse_names = _generate_random_horse_names(8) @@ -304,6 +306,9 @@ async def handle_test_simulate_race(bot: Bot, event: Event): except asyncio.TimeoutError: ticks = room.tick_count if room else 0 await test_simulate_race_cmd.finish(f"完全模拟失败:超时未完成(当前回合:{ticks})") + except asyncio.CancelledError: + ticks = room.tick_count if room else 0 + await test_simulate_race_cmd.finish(f"完全模拟失败:任务被取消(当前回合:{ticks})") except Exception as e: tail = "\n".join(traceback.format_exc().splitlines()[-8:]) await test_simulate_race_cmd.finish(f"完全模拟异常:{type(e).__name__}: {e}\n{tail}") @@ -314,3 +319,4 @@ async def handle_test_simulate_race(bot: Bot, event: Event): commands_mod.points_service = original_points_service commands_mod.message_service = original_message_service commands_mod.config.RACE_TICK_INTERVAL = original_tick_interval + commands_mod.race_engine.stop_race = original_stop_race