Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

feat(bot): replace fixed activity cycle with weighted random rotation#267

Merged
karaktaka merged 2 commits into
mainfrom
feature/random-activity-rotation
Feb 28, 2026
Merged

feat(bot): replace fixed activity cycle with weighted random rotation#267
karaktaka merged 2 commits into
mainfrom
feature/random-activity-rotation

Conversation

@karaktaka
Copy link
Copy Markdown
Contributor

@karaktaka karaktaka commented Feb 27, 2026

Summary

  • Replaces itertools.cycle + fixed @tasks.loop(minutes=5) with a plain asyncio task that owns its own sleep timing
  • Activity selection now uses random.choices with weights — "Use / for commands" variants are 3× more likely than flavor entries
  • Sleep interval between rotations is randomized between 2–7 minutes (random.uniform(120, 420))
  • Adds 4 new flavor activities for more variety

Why asyncio task instead of tasks.loop + change_interval

tasks.loop pre-computes _next_iteration before invoking the callback, so calling change_interval() inside the callback adjusts the iteration after next — not the upcoming sleep. A plain asyncio task with await sleep(...) owns its timing completely with no framework state to fight.

Test plan

  • Bot starts and shows "Use / for commands" as the initial activity
  • Activity changes every 2–7 minutes (observe over a few cycles)
  • "Use / for commands" variants appear noticeably more often than flavor strings
  • Bot reconnects cleanly without spawning duplicate activity loops (check on_ready guard)

🤖 Generated with Claude Code

Swaps the deterministic `itertools.cycle` + fixed 5-minute `tasks.loop`
for a plain asyncio task that picks activities via weighted `random.choices`
and sleeps a random 2–7 minutes between rotations. "Use / for commands"
variants carry 3× weight so they remain the most frequent status. Adds
four new flavor activities for more variety.

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread NerdyPy/bot.py Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@karaktaka karaktaka merged commit 5949fb8 into main Feb 28, 2026
7 checks passed
@karaktaka karaktaka deleted the feature/random-activity-rotation branch February 28, 2026 10:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant