fix: polish lottery dialog and moderation records

This commit is contained in:
ngfchl
2026-07-07 16:27:48 +08:00
parent 0169ac654d
commit 98e2ba60c6
11 changed files with 1087 additions and 8 deletions
+40 -2
View File
@@ -299,6 +299,44 @@ async def join_lottery_event(event_id: int, user_id: int, username: str = "", fi
return {"ok": True, "event": event, "count": count, "should_draw": event.end_type == "people" and count >= event.end_value}
def lottery_event_payload(event: LotteryEvent | None) -> dict | None:
if not event:
return None
return {
"id": event.id,
"chat_id": event.chat_id,
"title": event.title,
"prize": event.prize,
"description": event.description,
"condition_type": event.condition_type,
"condition_value": event.condition_value,
"end_type": event.end_type,
"end_value": event.end_value,
"draw_at": event.draw_at,
"status": event.status,
"winner_id": event.winner_id,
"winner_name": event.winner_name,
"ended_at": event.ended_at,
"created_at": event.created_at,
"updated_at": event.updated_at,
}
def lottery_participant_payload(p: LotteryParticipant | None) -> dict | None:
if not p:
return None
return {
"id": p.id,
"event_id": p.event_id,
"chat_id": p.chat_id,
"user_id": p.user_id,
"username": p.username,
"first_name": p.first_name,
"created_at": p.created_at,
"updated_at": p.updated_at,
}
async def draw_lottery_event(event_id: int) -> dict:
event = await LotteryEvent.filter(id=event_id).first()
if not event or event.status != "active":
@@ -308,11 +346,11 @@ async def draw_lottery_event(event_id: int) -> dict:
event.status = "cancelled"
event.ended_at = datetime.now()
await event.save()
return {"ok": False, "reason": "无人参与,抽奖已取消", "event": event}
return {"ok": False, "reason": "无人参与,抽奖已取消", "event": lottery_event_payload(event)}
winner = random.choice(participants)
event.status = "ended"
event.winner_id = winner.user_id
event.winner_name = winner.username or winner.first_name or str(winner.user_id)
event.ended_at = datetime.now()
await event.save()
return {"ok": True, "event": event, "winner": winner, "count": len(participants)}
return {"ok": True, "event": lottery_event_payload(event), "winner": lottery_participant_payload(winner), "count": len(participants)}