(client: TelegramClient, user: any, lottery: any, chatId: string)
| 427 | // Check avatar requirement |
| 428 | if (lottery.require_avatar) { |
| 429 | const userId = user.id || user; |
| 430 | const userEntity = await getEntityWithHash(client, userId); |
| 431 | if (userEntity && "photo" in userEntity && !userEntity.photo) { |
| 432 | return { valid: false, reason: "需要设置头像才能参与抽奖" }; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | // Check username requirement |
| 437 | if (lottery.require_username && !user.username) { |
| 438 | return { valid: false, reason: "需要设置用户名才能参与抽奖" }; |
| 439 | } |
| 440 | |
| 441 | // Check channel subscription requirement |
| 442 | if (lottery.required_channel) { |
| 443 | try { |
| 444 | const userId = user.id || user; |
| 445 | const channelEntity = await client.getEntity(lottery.required_channel); |
| 446 | const participant = await client.invoke( |
| 447 | new Api.channels.GetParticipant({ |
| 448 | channel: channelEntity, |
| 449 | participant: userId, |
| 450 | }) |
| 451 | ); |
| 452 | if (!participant) { |
| 453 | return { valid: false, reason: `需要关注频道 ${lottery.required_channel} 才能参与抽奖` }; |
| 454 | } |
| 455 | } catch (error) { |
| 456 | return { valid: false, reason: `需要关注指定频道才能参与抽奖` }; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | return { valid: true }; |
| 461 | } catch (error) { |
| 462 | console.error("Error validating user conditions:", error); |
| 463 | return { valid: true }; // Default to allow if validation fails |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // Prize distribution status functions |
| 468 | function updateWinnerStatus(winnerId: number, status: PrizeStatus, claimedAt?: number): void { |
| 469 | if (!db) return; |
| 470 | |
| 471 | const stmt = db.prepare(` |
| 472 | UPDATE lottery_winners |
| 473 | SET status = ?, claimed_at = ? |
| 474 | WHERE id = ? |
| 475 | `); |
| 476 | stmt.run(status, claimedAt || null, winnerId); |
| 477 | } |
no test coverage detected