Skip to content

feat: optional idle-leave-after-playback timeout#16

Closed
seitzbg wants to merge 5 commits into
dev-topsoil:mainfrom
seitzbg:feat/idle-leave-upstream
Closed

feat: optional idle-leave-after-playback timeout#16
seitzbg wants to merge 5 commits into
dev-topsoil:mainfrom
seitzbg:feat/idle-leave-upstream

Conversation

@seitzbg

@seitzbg seitzbg commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds an optional, default-off IDLE_LEAVE_TIMEOUT (seconds). When playback ends — a video finishing on its own or !stop — and nothing new starts within the timeout, the bot leaves voice and posts a short note. Unset / empty / 0 keeps current behavior (the bot stays in the channel).
  • Per-guild asyncio timer armed from the playback-cleanup (finally) blocks in cogs/stream.py (covers both the camera path and the go-live path). A fire-time guard re-checks the bot is genuinely idle (stream_tasks/live_connections empty, vc not playing, still connected) before disconnecting, so it never cuts off active or resumed playback. The go-live guard relies on stream_tasks/live_connections because go-live audio doesn't go through vc.play().
  • Starting new playback re-arms the timer (replacing any prior one); !leave and the auto-leave-on-empty handler cancel it. Pending timers are also cancelled on bot shutdown (SlopSoil.close()).

Changes

  • cogs/stream.py: _idle_leave_timeout, _format_idle, schedule_idle_leave, cancel_idle_leave, _idle_leave_after, _idle_leave_now; arm in both finally blocks.
  • bot.py: new idle_leave_tasks: dict[int, asyncio.Task], cancelled in close().
  • cogs/voice.py: cancel the timer on !leave and auto-leave-on-empty.
  • .env.example + README.md: document IDLE_LEAVE_TIMEOUT.
  • tests/test_idle_leave.py: new unit tests.

Test Plan

  • pytest — full suite green, including new tests/test_idle_leave.py (config parsing, duration formatting, schedule/re-arm/cancel, idle-guard no-ops, and !leave/auto-leave cancellation wiring).
  • Manual: IDLE_LEAVE_TIMEOUT=30, play a short clip, let it finish → bot leaves after ~30s and posts "left after 30 sec idle".
  • Manual: !stop mid-clip → bot leaves after the timeout; start new playback before it → bot stays.
  • Manual: !leave before the timeout → no spurious idle message; unset/0 → never auto-leaves (current behavior).

Merge note

Standalone on mainnot stacked, no dependency on #14 or #15. It does touch the README config table / .env block and cogs/stream.py, which #14 (stream profile / packet pacing) also touches, so whichever of #14 / #16 merges second will need a trivial rebase.

@seitzbg
seitzbg force-pushed the feat/idle-leave-upstream branch from 36a2b26 to 2a5c17b Compare June 3, 2026 22:42
@dev-topsoil

Copy link
Copy Markdown
Owner

@seitzbg this PR has been sitting stale as a draft for a while and the repo has gone through quite a few changes to the project structure since which may make a merge quite annoying.

I'm going to close the PR for now just for housekeeping reasons. If you want to get your clanker to re-do the PR I'm more than willing to add this feature to Slopsoil.

Also for what it's worth, I did try and reach out via email about linking up on Discord to discuss further features for the project but didn't hear anything back. I was out of town for a while so maybe I just didn't notice the reply or it got caught in a filter. Didn't want you to think I was ignoring you. The author info in my commits should be up to date if you want to reach out that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants