EveCogs/newhelpmenu/__init__.py
Rosie Val 93e759794f Fix NewHelpMenu: restore [p]help, close memory leak, parallelize perm checks
Loading this cog called bot.remove_command("help") with no replacement
command ever defined and no restore on unload — simply loading it broke
[p]help bot-wide, permanently, until process restart. Traced through Red's
own source (redbot/core/commands/help.py) and confirmed the default help
command already routes through bot.send_help_for(), which is exactly what
this cog hooks to render CV2 output — so the fix is to just not remove the
command at all; the CV2 conversion now actually works as intended too,
since its hook point is reachable again.

_active_views leaked one permanent dict entry (holding the whole rendered
page/embed list) per help/menu invocation — every on_timeout and "close"
button already called view.stop(), but nothing was popping the matching
entry except one specific code path. Added a single _track_view() helper
that wraps stop() for automatic eviction and applied it at all 5 insertion
points instead of just the one.

Parallelized the per-command can_run() permission checks in
gather_bot_help_data/gather_cog_help_data (previously one await at a time
for every bot/cog command on every single [p]help call). Also added the
admin_or_permissions check to `cv2 version`, the one subcommand missing it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-29 00:13:26 +01:00

15 lines
722 B
Python

from .newhelpmenu import NewHelpMenu
async def setup(bot):
# Red's own default help command (and any cog's ctx.send_help()) already
# routes through bot.send_help_for() internally — see
# redbot/core/commands/help.py. That's exactly the method this cog hooks
# to render CV2 output, so the built-in help command must stay in place
# for that hook to ever fire. Removing it here used to just delete
# [p]help bot-wide with nothing to replace it (there was never an actual
# replacement `help` command defined), and cog_unload never restored it
# either — simplest correct fix is to not remove it at all.
cog = NewHelpMenu(bot)
await bot.add_cog(cog)
await cog.initialize()