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:
+10
-5
@@ -18,23 +18,25 @@ async def cmd_help(bot, message):
|
|||||||
|
|
||||||
Usage: !help [command|plugin]
|
Usage: !help [command|plugin]
|
||||||
"""
|
"""
|
||||||
|
channel = message.target if message.is_channel else None
|
||||||
parts = message.text.split(None, 2)
|
parts = message.text.split(None, 2)
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
name = parts[1].lower().lstrip(bot.prefix)
|
name = parts[1].lower().lstrip(bot.prefix)
|
||||||
|
|
||||||
# Check command first
|
# Check command first
|
||||||
handler = bot.registry.commands.get(name)
|
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."
|
help_text = handler.help or "No help available."
|
||||||
await bot.reply(message, f"{bot.prefix}{name} -- {help_text}")
|
await bot.reply(message, f"{bot.prefix}{name} -- {help_text}")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check plugin
|
# Check plugin
|
||||||
module = bot.registry._modules.get(name)
|
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()
|
desc = (getattr(module, "__doc__", "") or "").split("\n")[0].strip()
|
||||||
cmds = sorted(
|
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]
|
lines = [f"{name} -- {desc}" if desc else name]
|
||||||
if cmds:
|
if cmds:
|
||||||
@@ -45,8 +47,11 @@ async def cmd_help(bot, message):
|
|||||||
await bot.reply(message, f"Unknown command or plugin: {name}")
|
await bot.reply(message, f"Unknown command or plugin: {name}")
|
||||||
return
|
return
|
||||||
|
|
||||||
# List all commands
|
# List all commands visible in this channel
|
||||||
names = sorted(bot.registry.commands.keys())
|
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)}")
|
await bot.reply(message, f"Commands: {', '.join(bot.prefix + n for n in names)}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user