fixbug:解决抢答和获取任务的问题
This commit is contained in:
@@ -220,7 +220,7 @@ def submit_answer(group_id, player_id, task_id, answer):
|
|||||||
return (
|
return (
|
||||||
f"😔 哎呀,小伙伴\n"
|
f"😔 哎呀,小伙伴\n"
|
||||||
f"🌼 群 {group_id} 的任务 task_{active_task_id} 不见了\n"
|
f"🌼 群 {group_id} 的任务 task_{active_task_id} 不见了\n"
|
||||||
f"🎀 可能已经被抢答啦!"
|
f"🎀 可能已经被抢答或过期啦!"
|
||||||
)
|
)
|
||||||
|
|
||||||
if task_data['status'] == 'completed':
|
if task_data['status'] == 'completed':
|
||||||
@@ -245,8 +245,9 @@ def submit_answer(group_id, player_id, task_id, answer):
|
|||||||
description = result["description"]
|
description = result["description"]
|
||||||
is_correct = points > 0
|
is_correct = points > 0
|
||||||
|
|
||||||
# 记录历史并更新积分
|
# 处理答案提交逻辑
|
||||||
if is_correct:
|
if is_correct:
|
||||||
|
# 答对 situation
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"UPDATE t_encyclopedia_players SET points = points + %s WHERE group_id = %s AND player_id = %s",
|
"UPDATE t_encyclopedia_players SET points = points + %s WHERE group_id = %s AND player_id = %s",
|
||||||
(points, group_id, player_id)
|
(points, group_id, player_id)
|
||||||
@@ -255,14 +256,16 @@ def submit_answer(group_id, player_id, task_id, answer):
|
|||||||
"UPDATE t_encyclopedia_active_tasks SET status = 'completed' WHERE group_id = %s AND active_task_id = %s",
|
"UPDATE t_encyclopedia_active_tasks SET status = 'completed' WHERE group_id = %s AND active_task_id = %s",
|
||||||
(group_id, active_task_id)
|
(group_id, active_task_id)
|
||||||
)
|
)
|
||||||
|
if player_id == holder_id:
|
||||||
message = (
|
message = (
|
||||||
f"🎉 {player_name} 太棒啦!\n"
|
f"🎉 {player_name} 太棒啦!\n"
|
||||||
f"🌟 任务:{question}\n"
|
f"🌟 任务:{question}\n"
|
||||||
f"🎈 答对了,真厉害!\n"
|
f"🎈 答对了,真厉害!\n"
|
||||||
f"🌈 奖励:{points} 分\n"
|
f"🌈 奖励:{points} 分\n"
|
||||||
f"🎀 提示:{description}"
|
f"🎀 提示:{description}"
|
||||||
if player_id == holder_id
|
)
|
||||||
else
|
else:
|
||||||
|
message = (
|
||||||
f"🎉 {player_name} 抢答成功!\n"
|
f"🎉 {player_name} 抢答成功!\n"
|
||||||
f"🌟 任务:{question}\n"
|
f"🌟 任务:{question}\n"
|
||||||
f"🎈 原主:{holder_name}\n"
|
f"🎈 原主:{holder_name}\n"
|
||||||
@@ -270,7 +273,7 @@ def submit_answer(group_id, player_id, task_id, answer):
|
|||||||
f"🎀 提示:{description}"
|
f"🎀 提示:{description}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# 错误扣1分,确保积分不低于0
|
# 答错 situation,任务保持 pending 状态,允许其他玩家继续抢答
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"UPDATE t_encyclopedia_players SET points = GREATEST(points - 1, 0) WHERE group_id = %s AND player_id = %s",
|
"UPDATE t_encyclopedia_players SET points = GREATEST(points - 1, 0) WHERE group_id = %s AND player_id = %s",
|
||||||
(group_id, player_id)
|
(group_id, player_id)
|
||||||
@@ -282,9 +285,11 @@ def submit_answer(group_id, player_id, task_id, answer):
|
|||||||
f"🎈 你答:{answer}\n"
|
f"🎈 你答:{answer}\n"
|
||||||
f"🌟 正确答案:{correct_answer_db}\n"
|
f"🌟 正确答案:{correct_answer_db}\n"
|
||||||
f"🌈 扣 1 分,别灰心!\n"
|
f"🌈 扣 1 分,别灰心!\n"
|
||||||
f"🎀 提示:{description}"
|
f"🎀 提示:{description}\n"
|
||||||
|
f"🌟 任务 task_{active_task_id} 仍可抢答哦!"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 记录提交历史
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"INSERT INTO t_encyclopedia_task_history (group_id, active_task_id, player_id, answer, is_correct, points_earned) VALUES (%s, %s, %s, %s, %s, %s)",
|
"INSERT INTO t_encyclopedia_task_history (group_id, active_task_id, player_id, answer, is_correct, points_earned) VALUES (%s, %s, %s, %s, %s, %s)",
|
||||||
(group_id, active_task_id, player_id, answer, is_correct, points)
|
(group_id, active_task_id, player_id, answer, is_correct, points)
|
||||||
@@ -458,18 +463,9 @@ def setup_schedule():
|
|||||||
|
|
||||||
# 主程序
|
# 主程序
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# # 初始化群聊
|
# 测试抢答功能
|
||||||
# print(add_group("group1", "admin1"))
|
print(game_process_message("47530198896@chatroom", "player1001", "/start", "玩家1"))
|
||||||
# print(add_group("group2", "admin1"))
|
print(game_process_message("47530198896@chatroom", "player1002", "/start", "玩家2"))
|
||||||
#
|
|
||||||
# # 初始化玩家
|
|
||||||
# print(game_process_message("group1", "player1001", "/start", "玩家1"))
|
|
||||||
# print(game_process_message("group1", "player1002", "/start", "玩家2"))
|
|
||||||
# print(game_process_message("group2", "player2001", "/start", "玩家A"))
|
|
||||||
# print(game_process_message("group2", "player2002", "/start", "玩家B"))
|
|
||||||
#
|
|
||||||
# # 设置调度
|
|
||||||
# setup_schedule()
|
|
||||||
|
|
||||||
# 测试 /gettask
|
|
||||||
print(game_process_message("47530198896@chatroom", "player1001", "/gettask"))
|
print(game_process_message("47530198896@chatroom", "player1001", "/gettask"))
|
||||||
|
# 玩家2 抢答玩家1的任务
|
||||||
|
print(game_process_message("47530198896@chatroom", "player1002", "/answer 1 珠穆朗玛峰"))
|
||||||
Reference in New Issue
Block a user