feat(horse_racing): 实现赛马消息更新替换与自动撤回
重构消息发送逻辑,引入消息类型区分和自动撤回机制。赛马进度更新现在会替换前一条更新消息,避免消息刷屏;比赛结果发送前自动撤回最后一条进度更新,提升聊天体验。同时支持配置不同消息类型的自动撤回时间。 - 新增 MessageService.send_with_recall 方法统一处理消息发送和撤回 - 添加 recall_previous_of_type 方法用于撤回特定类型的上一条消息 - 修改 _send_to_scope 函数支持消息类型参数 - 更新测试代码以适配新的消息发送接口
This commit is contained in:
@@ -195,6 +195,12 @@ class _NoopMessageService:
|
||||
def clear_pending_recalls(self, scope: str):
|
||||
return
|
||||
|
||||
async def send_with_recall(self, bot, scope, message_type, message):
|
||||
return "fake_msg_id"
|
||||
|
||||
async def recall_previous_of_type(self, bot, scope, message_type):
|
||||
return
|
||||
|
||||
|
||||
@test_simulate_race_cmd.handle()
|
||||
async def handle_test_simulate_race(bot: Bot, event: Event):
|
||||
@@ -240,7 +246,7 @@ async def handle_test_simulate_race(bot: Bot, event: Event):
|
||||
progress_count = 0
|
||||
max_progress = 30
|
||||
|
||||
async def _test_send_to_scope(_bot: Bot, _scope: str, message: str):
|
||||
async def _test_send_to_scope(_bot: Bot, _scope: str, message: str, *args, **kwargs):
|
||||
nonlocal progress_count
|
||||
await fake_bot.send_msg(message_type="private", user_id=event.user_id, message=message)
|
||||
if not stream_progress:
|
||||
@@ -250,7 +256,7 @@ async def handle_test_simulate_race(bot: Bot, event: Event):
|
||||
progress_count += 1
|
||||
if progress_count > max_progress:
|
||||
return
|
||||
await original_send_to_scope(bot, scope, message)
|
||||
await original_send_to_scope(bot, scope, message, *args, **kwargs)
|
||||
|
||||
commands_mod._send_to_scope = _test_send_to_scope
|
||||
|
||||
|
||||
Reference in New Issue
Block a user