fix: filter help output by per-channel plugin config
!help now only lists commands from plugins allowed in the current channel. !help <cmd> and !help <plugin> return "unknown" for filtered plugins. PMs remain unrestricted.
This commit is contained in:
@@ -18,23 +18,25 @@ async def cmd_help(bot, message):
|
||||
|
||||
Usage: !help [command|plugin]
|
||||
"""
|
||||
channel = message.target if message.is_channel else None
|
||||
parts = message.text.split(None, 2)
|
||||
if len(parts) > 1:
|
||||
name = parts[1].lower().lstrip(bot.prefix)
|
||||
|
||||
# Check command first
|
||||
handler = bot.registry.commands.get(name)
|
||||
if handler:
|
||||
if handler and bot._plugin_allowed(handler.plugin, channel):
|
||||
help_text = handler.help or "No help available."
|
||||
await bot.reply(message, f"{bot.prefix}{name} -- {help_text}")
|
||||
return
|
||||
|
||||
# Check plugin
|
||||
module = bot.registry._modules.get(name)
|
||||
if module:
|
||||
if module and bot._plugin_allowed(name, channel):
|
||||
desc = (getattr(module, "__doc__", "") or "").split("\n")[0].strip()
|
||||
cmds = sorted(
|
||||
k for k, v in bot.registry.commands.items() if v.plugin == name
|
||||
k for k, v in bot.registry.commands.items()
|
||||
if v.plugin == name and bot._plugin_allowed(v.plugin, channel)
|
||||
)
|
||||
lines = [f"{name} -- {desc}" if desc else name]
|
||||
if cmds:
|
||||
@@ -45,8 +47,11 @@ async def cmd_help(bot, message):
|
||||
await bot.reply(message, f"Unknown command or plugin: {name}")
|
||||
return
|
||||
|
||||
# List all commands
|
||||
names = sorted(bot.registry.commands.keys())
|
||||
# List all commands visible in this channel
|
||||
names = sorted(
|
||||
k for k, v in bot.registry.commands.items()
|
||||
if bot._plugin_allowed(v.plugin, channel)
|
||||
)
|
||||
await bot.reply(message, f"Commands: {', '.join(bot.prefix + n for n in names)}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user