Skip to content

Commit 419a0dc

Browse files
committed
feat: add _auto_enter_users trigger after pot win
1 parent 286c6ce commit 419a0dc

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

luckypot/game.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
POT_ENTRY_COST = 5
1313
DAILY_DRAW_CHANCE = 0.95
1414
RANDOM_WIN_CHANCE = 0.025
15+
AUTO_ENTER_DELAY_SECONDS = 30
1516

1617
# Per-guild lock to serialize pot mutations (entries, instant wins, draws).
1718
# Prevents race conditions like a daily draw and instant-win confirmation
@@ -245,6 +246,7 @@ async def process_pot_win(
245246
elif announce_fn:
246247
suffix = f" ({win_type})" if win_type != "DAILY DRAW" else ""
247248
await announce_fn(f"<@{winner_id}> won {winning_amount} STK!{suffix}")
249+
asyncio.create_task(_auto_enter_users(guild_id, announce_fn=announce_fn))
248250
else:
249251
logger.error(f"Failed to send winnings to {winner_id}, pot remains active")
250252
if announce_fn:
@@ -279,6 +281,34 @@ async def _dramatic_draw_reveal(
279281
)
280282

281283

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+
282312
async def end_pot_with_winner(
283313
guild_id: str,
284314
win_type: str = "DAILY DRAW",

0 commit comments

Comments
 (0)