整理代码

This commit is contained in:
liuwei
2025-03-18 15:48:14 +08:00
parent ede83d6c94
commit 21f8fffca8
2 changed files with 15 additions and 24 deletions

View File

@@ -63,7 +63,7 @@ def assign_random_task(group_id, player_id=None):
try:
# 获取群内所有玩家
players = encyclopedia_db.get_all_players_in_group(group_id)
if not players:
message = (
f"😔 哎呀,群 {group_id} 静悄悄\n"
@@ -152,7 +152,7 @@ def submit_answer(group_id, player_id, task_id, answer):
# 获取任务信息
task_data = encyclopedia_db.get_task_by_id(group_id, active_task_id)
if not task_data:
message = (
f"😔 哎哟,任务 task_{active_task_id} 不翼而飞啦!\n"
@@ -186,10 +186,10 @@ def submit_answer(group_id, player_id, task_id, answer):
if is_correct:
# 更新玩家积分
encyclopedia_db.update_player_points(player_id, group_id, points)
# 完成任务
encyclopedia_db.complete_task(active_task_id)
if player_id == holder_id:
message = (
f"🎉 {player_name} 你是天才吗?\n"
@@ -249,14 +249,14 @@ def show_rank(group_id, player_id):
try:
# 获取排行榜
ranks = encyclopedia_db.get_player_ranking(group_id, 10)
if not ranks:
message = (
f"😔 群 {group_id} 冷冷清清\n"
f"🌟 快来一起燥起来吧!"
)
return {"message": message, "player_id": player_id}
rank_text = f"🎉 群 {group_id} 排行榜Top 10来啦\n"
for i, row in enumerate(ranks, 1):
rank_text += f"🐓 {i}. {row['player_name']}: {row['points']}\n"
@@ -272,14 +272,14 @@ def show_active_tasks(group_id, player_id):
try:
# 获取活跃任务
tasks = encyclopedia_db.get_active_tasks_in_group(group_id)
if not tasks:
message = (
f"😄 群 {group_id} 现在一片祥和\n"
f"🌟 没任务?快用 /t 搞一个!"
)
return {"message": message, "player_id": player_id}
task_text = f"🎉 群 {group_id} 活跃任务速递:\n"
for task in tasks:
task_text += (
@@ -299,14 +299,14 @@ def list_uncompleted_tasks(group_id, player_id):
try:
# 获取未完成任务
tasks = encyclopedia_db.get_active_tasks_in_group(group_id)
if not tasks:
message = (
f"😄 群 {group_id} 全员开挂?\n"
f"🌟 没未完成任务,快用 /t 再战!"
)
return {"message": message, "player_id": player_id}
task_text = f"🎉 群 {group_id} 未完成任务大曝光:\n"
for task in tasks:
task_text += (
@@ -425,4 +425,4 @@ if __name__ == "__main__":
# 测试用例
print(game_process_message("45317011307@chatroom", "Jyunere", "/t")) # 新用户获取任务
print(game_process_message("45317011307@chatroom", "Jyunere", "/a 18 罗马斗兽场")) # 提交答案
print(game_process_message("45317011307@chatroom", "Jyunere", "/r")) # 查看排行榜
print(game_process_message("45317011307@chatroom", "Jyunere", "/r")) # 查看排行榜