Skip to content

Commit 8a6ab07

Browse files
committed
Fix help command for external plugins
1 parent 20cbc08 commit 8a6ab07

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# v2.18.5
8+
9+
Fix help command bug when using external plugins.
10+
711
# v2.18.4
812

913
Fix the teams permission bug.

bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
__version__ = '2.18.4'
25+
__version__ = '2.18.5'
2626

2727
import asyncio
2828
import logging

cogs/utility.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from core.decorators import github_access_token_required, trigger_typing
2323
from core.models import Bot, InvalidConfigError, PermissionLevel
2424
from core.paginator import PaginatorSession, MessagePaginatorSession
25-
from core.utils import cleanup_code, info, error, User
25+
from core.utils import cleanup_code, info, error, User, perms_level
2626

2727
logger = logging.getLogger('Modmail')
2828

@@ -38,17 +38,12 @@ async def format_cog_help(self, ctx, cog):
3838

3939
prefix = self.bot.prefix
4040

41-
def perms_required(cmd):
42-
for c in cmd.checks:
43-
return getattr(c, 'permission_level', 0)
44-
return 0
45-
4641
fmts = ['']
4742
for cmd in sorted(self.bot.commands,
48-
key=lambda cmd: perms_required(cmd)):
43+
key=lambda cmd: perms_level(cmd)):
4944
if cmd.instance is cog and not cmd.hidden:
5045
new_fmt = f'`{prefix + cmd.qualified_name}` '
51-
perm_level = perms_required(cmd)
46+
perm_level = perms_level(cmd)
5247
if perm_level is not None:
5348
new_fmt = f'`[{perm_level}] {prefix + cmd.qualified_name}` '
5449

@@ -88,7 +83,7 @@ async def format_command_help(self, cmd):
8883

8984
prefix = self.bot.prefix
9085

91-
perm_level = next(getattr(c, 'permission_level', None) for c in cmd.checks)
86+
perm_level = perms_level(cmd)
9287
perm_level = f'{perm_level.name} [{perm_level}]' if perm_level is not None else ''
9388

9489
embed = Embed(

core/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PermissionLevel(IntEnum):
2020
MOD = 3
2121
SUPPORTER = 2
2222
REGULAR = 1
23+
NONE = 0
2324

2425

2526
class Bot(abc.ABC, commands.Bot):

core/utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from discord.ext import commands
77

88
from colorama import Fore, Style
9+
from core.models import PermissionLevel
910

1011

1112
def info(*msgs):
@@ -186,6 +187,15 @@ def match_user_id(text: str) -> int:
186187
return int(match.group(1))
187188
return -1
188189

190+
def perms_level(cmd):
191+
for c in cmd.checks:
192+
perm = getattr(c, 'permission_level', None)
193+
if perm is not None:
194+
return perm
195+
for c in cmd.checks:
196+
if 'is_owner' in str(c):
197+
return PermissionLevel.OWNER
198+
return PermissionLevel.NONE
189199

190200
async def ignore(coro):
191201
try:

0 commit comments

Comments
 (0)