| 324 | distribution_mode, claim_timeout, delete_delay, require_avatar, |
| 325 | require_username, required_channel, prize_warehouse, allow_bots, |
| 326 | member_filter, auto_draw_time, created_at, creator_id, unique_id |
| 327 | ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 328 | `); |
| 329 | |
| 330 | const result = stmt.run( |
| 331 | config.chat_id, config.title, config.keyword, config.max_participants, |
| 332 | config.winner_count, config.mode, config.distribution_mode, config.claim_timeout, |
| 333 | config.delete_delay, config.require_avatar ? 1 : 0, config.require_username ? 1 : 0, |
| 334 | config.required_channel || null, config.prize_warehouse || 'default', config.allow_bots ? 1 : 0, |
| 335 | config.member_filter || null, config.auto_draw_time || null, Date.now(), config.creator_id, |
| 336 | config.unique_id |
| 337 | ); |
| 338 | |
| 339 | return result.lastInsertRowid as number; |
| 340 | } |
| 341 | |
| 342 | function getActiveLottery(chatId: string): any | null { |
| 343 | if (!db) return null; |
| 344 | |
| 345 | const stmt = db.prepare(` |
| 346 | SELECT * FROM lottery_config |
| 347 | WHERE chat_id = ? AND status = 'active' |
| 348 | ORDER BY created_at DESC LIMIT 1 |
| 349 | `); |
| 350 | return stmt.get(chatId) as any; |
| 351 | } |