新增冒险查看倒计时

This commit is contained in:
2025-11-12 16:37:10 +08:00
parent 8fd8850ecf
commit b59931adcf
3 changed files with 91 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
from __future__ import annotations
from datetime import datetime
from typing import Optional
from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig
@@ -151,11 +152,49 @@ class WPSCombatAdventure(WPSCombatBase):
current_adventure_id = status.get("current_adventure_id")
if current_adventure_id:
return await self.send_markdown_message(
"❌ 你已经在冒险中,请等待当前冒险完成",
chat_id,
user_id
)
adventure = service.get_adventure_by_id(current_adventure_id)
if not adventure:
return await self.send_markdown_message(
(
"❌ 你已经在冒险中,但未找到相关记录,请稍后重试或联系管理员。"
f"\n- 冒险ID{current_adventure_id}"
),
chat_id,
user_id
)
expected_end_str = adventure.get("expected_end_time")
try:
expected_end = datetime.fromisoformat(expected_end_str) if expected_end_str else None
except (TypeError, ValueError):
expected_end = None
if expected_end:
remaining_seconds = (expected_end - datetime.now()).total_seconds()
if remaining_seconds <= 0:
message = [
"⏳ 当前冒险已进入结算,请稍候等待系统发放结果。",
f"- 冒险ID{current_adventure_id}",
f"- 预计完成:{expected_end.strftime('%Y-%m-%d %H:%M')}"
]
else:
remaining_minutes = int((remaining_seconds + 59) // 60)
remaining_text = (
"不到 1 分钟" if remaining_minutes == 0 else f"{remaining_minutes} 分钟"
)
message = [
"⏳ 你已经在冒险中,请等待当前冒险完成。",
f"- 冒险ID{current_adventure_id}",
f"- 剩余时间:{remaining_text}",
f"- 预计完成:{expected_end.strftime('%Y-%m-%d %H:%M')}"
]
else:
message = [
"❌ 你已经在冒险中,但无法解析预计结束时间,请稍后重试。",
f"- 冒险ID{current_adventure_id}"
]
return await self.send_markdown_message("\n".join(message), chat_id, user_id)
last_record = service.get_last_adventure_record(user_id)
if not last_record:

View File

@@ -639,6 +639,18 @@ class CombatService:
row = cursor.fetchone()
return dict(row) if row else None
def get_adventure_by_id(self, adventure_id: int) -> Optional[Dict[str, Any]]:
"""
根据冒险ID获取冒险记录
"""
cursor = self._db.conn.cursor()
cursor.execute(
"SELECT * FROM combat_adventure_records WHERE adventure_id = ?",
(adventure_id,),
)
row = cursor.fetchone()
return dict(row) if row else None
def start_adventure(
self,
user_id: int,