1.修改ai返回格式为markdown2.新增冒险放弃指令
This commit is contained in:
@@ -56,6 +56,10 @@ class AdventureGame(BaseGame):
|
||||
if args in ['help', '帮助', 'info']:
|
||||
return self._get_adventure_help()
|
||||
|
||||
# 放弃当前冒险(按最低倍率结算已冒险时间)
|
||||
if args in ['abandon', '放弃']:
|
||||
return await self._abandon_adventure(chat_id, user_id)
|
||||
|
||||
# 默认:冒险耗时1分钟
|
||||
else:
|
||||
# 解析消耗时间
|
||||
@@ -170,6 +174,69 @@ class AdventureGame(BaseGame):
|
||||
|
||||
return text
|
||||
|
||||
async def _abandon_adventure(self, chat_id: int, user_id: int) -> str:
|
||||
"""放弃当前冒险,按最低倍率结算已冒险时间
|
||||
|
||||
Args:
|
||||
chat_id: 会话ID(使用0作为用户级标识)
|
||||
user_id: 用户ID
|
||||
|
||||
Returns:
|
||||
放弃结果消息
|
||||
"""
|
||||
try:
|
||||
# 查询冒险状态
|
||||
state = self.db.get_game_state(0, user_id, 'adventure')
|
||||
if not state:
|
||||
return "❌ 当前没有进行中的冒险,可使用 `.adventure` 开始新的冒险。"
|
||||
|
||||
state_data = state.get('state_data', {})
|
||||
start_time = state_data.get('start_time')
|
||||
cost_time = state_data.get('cost_time')
|
||||
if start_time is None or cost_time is None:
|
||||
# 状态异常,清理并提示
|
||||
self.db.delete_game_state(0, user_id, 'adventure')
|
||||
return "⚠️ 冒险状态异常已清理,请使用 `.adventure` 重新开始。"
|
||||
|
||||
current_time = int(time.time())
|
||||
elapsed_seconds = max(0, current_time - int(start_time))
|
||||
elapsed_minutes = elapsed_seconds // 60
|
||||
if elapsed_minutes < 1:
|
||||
elapsed_minutes = 1
|
||||
|
||||
# 计算最低倍率
|
||||
try:
|
||||
min_multiplier = min(m for _, m, _ in self.prize_pool)
|
||||
except Exception:
|
||||
# 兜底:若奖池异常,按0.5处理
|
||||
min_multiplier = 0.5
|
||||
|
||||
reward_points = int(min_multiplier * elapsed_minutes)
|
||||
if reward_points < 0:
|
||||
reward_points = 0
|
||||
|
||||
# 发放奖励并清理状态
|
||||
if reward_points > 0:
|
||||
self.db.add_points(user_id, reward_points, "adventure", "冒险放弃奖励")
|
||||
self.db.delete_game_state(0, user_id, 'adventure')
|
||||
|
||||
# 查询当前积分
|
||||
updated_points = self.db.get_user_points(user_id)
|
||||
|
||||
# 输出
|
||||
text = f"## ⚡️ 冒险放弃\n\n"
|
||||
text += f"**已计入时间**: {elapsed_minutes} 分钟\n\n"
|
||||
text += f"**最低倍率**: {min_multiplier} 倍\n\n"
|
||||
text += f"**获得积分**: {reward_points} 分\n\n"
|
||||
text += f"**当前积分**: {updated_points['points']} 分\n\n"
|
||||
text += "---\n\n"
|
||||
text += "💡 提示:可随时使用 `.adventure` 再次踏上冒险之旅!"
|
||||
return text
|
||||
except Exception as e:
|
||||
logger.error(f"放弃冒险时出错: {e}", exc_info=True)
|
||||
# 失败时不影响原状态,返回提示
|
||||
return f"❌ 放弃冒险失败:{str(e)}"
|
||||
|
||||
def _draw_prize(self, prize_pool: list) -> dict:
|
||||
"""从奖品池中抽取奖品
|
||||
|
||||
@@ -209,6 +276,8 @@ class AdventureGame(BaseGame):
|
||||
text += f"- `.adventure time` - 消耗time分钟进行冒险, 最少一分钟\n"
|
||||
|
||||
text += f"### 其他功能\n"
|
||||
text += f"- `.adventure abandon` - 放弃当前冒险,按最低倍率结算已冒险时间\n"
|
||||
text += f"- `.adventure 放弃` - 放弃当前冒险,按最低倍率结算已冒险时间\n"
|
||||
text += f"- `.adventure help` - 查看帮助\n\n"
|
||||
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user