|
12 | 12 | POT_ENTRY_COST = 5 |
13 | 13 | DAILY_DRAW_CHANCE = 0.95 |
14 | 14 | RANDOM_WIN_CHANCE = 0.025 |
| 15 | +AUTO_ENTER_DELAY_SECONDS = 30 |
15 | 16 |
|
16 | 17 | # Per-guild lock to serialize pot mutations (entries, instant wins, draws). |
17 | 18 | # Prevents race conditions like a daily draw and instant-win confirmation |
@@ -245,6 +246,7 @@ async def process_pot_win( |
245 | 246 | elif announce_fn: |
246 | 247 | suffix = f" ({win_type})" if win_type != "DAILY DRAW" else "" |
247 | 248 | await announce_fn(f"<@{winner_id}> won {winning_amount} STK!{suffix}") |
| 249 | + asyncio.create_task(_auto_enter_users(guild_id, announce_fn=announce_fn)) |
248 | 250 | else: |
249 | 251 | logger.error(f"Failed to send winnings to {winner_id}, pot remains active") |
250 | 252 | if announce_fn: |
@@ -279,6 +281,34 @@ async def _dramatic_draw_reveal( |
279 | 281 | ) |
280 | 282 |
|
281 | 283 |
|
| 284 | +async def _auto_enter_users(guild_id: str, announce_fn: AnnounceFn = None) -> None: |
| 285 | + """Wait briefly then auto-enter all opted-in users for a guild. |
| 286 | +
|
| 287 | + Called as a fire-and-forget task after a pot win is announced. |
| 288 | + Uses the existing enter_pot() which handles all edge cases (bans, |
| 289 | + already-entered, STK account missing, etc.). |
| 290 | + """ |
| 291 | + await asyncio.sleep(AUTO_ENTER_DELAY_SECONDS) |
| 292 | + |
| 293 | + conn = db.get_connection() |
| 294 | + try: |
| 295 | + discord_ids = db.get_auto_enter_users(conn, guild_id) |
| 296 | + finally: |
| 297 | + conn.close() |
| 298 | + |
| 299 | + if not discord_ids: |
| 300 | + return |
| 301 | + |
| 302 | + logger.info( |
| 303 | + f"Auto-entering {len(discord_ids)} user(s) into new pot for guild {guild_id}" |
| 304 | + ) |
| 305 | + for discord_id in discord_ids: |
| 306 | + result = await enter_pot(discord_id, guild_id, announce_fn=announce_fn) |
| 307 | + logger.info( |
| 308 | + f"Auto-enter for discord_id={discord_id} guild={guild_id}: status={result['status']}" |
| 309 | + ) |
| 310 | + |
| 311 | + |
282 | 312 | async def end_pot_with_winner( |
283 | 313 | guild_id: str, |
284 | 314 | win_type: str = "DAILY DRAW", |
|
0 commit comments