Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for situationally broken apropos command #1711 #1712

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ fixes:
- chore: bump setuptools to 75.7.0 (#1709)
- chore: bump pyOpenSSL to 24.3.0 (#1710)
- chore: bump jinja2 to 3.1.5 and requests to 2.32.0 (#1714)
- Fix: situationally broken apropos command (#1711)


v6.2.0 (2024-01-01)
-------------------
Expand Down
24 changes: 11 additions & 13 deletions errbot/core_plugins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def is_git_directory(self, path="."):

return tags.pop(-1) if tags is not None else None

def may_access_command(self, m, cmd):
m, _, _ = self._bot._process_command_filters(
msg=m, cmd=cmd, args=None, dry_run=True
)
return m is not None

# noinspection PyUnusedLocal
@botcmd(template="about")
def about(self, msg, args):
Expand Down Expand Up @@ -52,7 +58,7 @@ def apropos(self, msg, args):
commands = cls_commands.get(cls, [])
if (
not self.bot_config.HIDE_RESTRICTED_COMMANDS
or self._bot.check_command_access(msg, name)[0]
or self.may_access_command(msg, name)
):
commands.append((name, command))
cls_commands[cls] = commands
Expand Down Expand Up @@ -86,15 +92,6 @@ def help(self, msg, args):
"""Returns a help string listing available options.
Automatically assigned to the "help" command."""

def may_access_command(m, cmd):
m, _, _ = self._bot._process_command_filters(
msg=m, cmd=cmd, args=None, dry_run=True
)
return m is not None

def get_name(named):
return named.__name__.lower()

# Normalize args to lowercase for ease of use
args = args.lower() if args else ""
usage = ""
Expand All @@ -105,8 +102,9 @@ def get_name(named):
cls = self._bot.get_plugin_class_from_method(command)
obj = command.__self__
_, commands = cls_obj_commands.get(cls, (None, []))
if not self.bot_config.HIDE_RESTRICTED_COMMANDS or may_access_command(
msg, name
if (
not self.bot_config.HIDE_RESTRICTED_COMMANDS
or self.may_access_command(msg, name)
):
commands.append((name, command))
cls_obj_commands[cls] = (obj, commands)
Expand Down Expand Up @@ -163,7 +161,7 @@ def get_name(named):
if command._err_command_hidden:
continue

if not may_access_command(msg, name):
if not self.may_access_command(msg, name):
continue
pairs.append((name, command))

Expand Down