Skip to content

Commit cd94027

Browse files
committed
Fixed a typo, changed help message to include all commands
1 parent 2ea2246 commit cd94027

File tree

3 files changed

+37
-48
lines changed

3 files changed

+37
-48
lines changed

CHANGELOG.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- A brand new permission system! Replacing the old guild-based permissions (ie. manage channels, manage messages), the new system enables you to customize your desire permission level specific to a command or a group of commands for a role or user.
1313
- There are five permission groups/levels:
14-
- Owner
15-
- Administrator
16-
- Moderator
17-
- Supporter
18-
- Regular
14+
- Owner [5]
15+
- Administrator [4]
16+
- Moderator [3]
17+
- Supporter [2]
18+
- Regular [1]
1919

2020
You may add a role or user to a permission group through any of the following methods:
2121
- `?permissions add level owner @role`
@@ -36,6 +36,8 @@ To view all roles and users with permission for a permission group or command do
3636

3737
By default, all newly set up Modmail will have `OWNER` set to the owner of the bot, and `EGULAR` set to @everyone.
3838

39+
The help message no longer conceal inaccessible commands due to check failures.
40+
3941
### Note
4042

4143
When updating to this version, all prior permission settings with guild-based permissions will be invalidated. You will need to convert to the above system.

cogs/utility.py

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from json import JSONDecodeError
1111
from textwrap import indent
1212

13-
import discord
1413
from discord import Embed, Color, Activity
1514
from discord.enums import ActivityType, Status
1615
from discord.ext import commands
@@ -28,23 +27,11 @@
2827

2928

3029
class Utility:
31-
"""General commands that provide utility"""
30+
"""General commands that provide utility."""
3231

3332
def __init__(self, bot: Bot):
3433
self.bot = bot
3534

36-
@staticmethod
37-
async def verify_checks(ctx, cmd):
38-
predicates = cmd.checks
39-
if not predicates:
40-
return True
41-
42-
try:
43-
return await discord.utils.async_all(predicate(ctx)
44-
for predicate in predicates)
45-
except commands.CheckFailure:
46-
return False
47-
4835
async def format_cog_help(self, ctx, cog):
4936
"""Formats the text for a cog help"""
5037

@@ -53,10 +40,13 @@ async def format_cog_help(self, ctx, cog):
5340
fmts = ['']
5441
for cmd in sorted(self.bot.commands,
5542
key=lambda cmd: cmd.qualified_name):
56-
if cmd.instance is cog and not cmd.hidden and \
57-
await self.verify_checks(ctx, cmd):
58-
new_fmt = f'`{prefix + cmd.qualified_name}` - '
59-
new_fmt += f'{cmd.short_doc}\n'
43+
if cmd.instance is cog and not cmd.hidden:
44+
new_fmt = f'`{prefix + cmd.qualified_name}` '
45+
perm_level = next(getattr(c, 'permission_level', None) for c in cmd.checks)
46+
if perm_level is not None:
47+
new_fmt += f'[{perm_level}] '
48+
49+
new_fmt += f'- {cmd.short_doc}\n'
6050
if len(new_fmt) + len(fmts[-1]) >= 1024:
6151
fmts.append(new_fmt)
6252
else:
@@ -81,19 +71,21 @@ async def format_cog_help(self, ctx, cog):
8171
embeds.append(embed)
8272
return embeds
8373

84-
async def format_command_help(self, ctx, cmd):
74+
async def format_command_help(self, cmd):
8575
"""Formats command help."""
86-
if cmd.hidden or not await self.verify_checks(ctx, cmd):
76+
if cmd.hidden:
8777
return None
8878

8979
prefix = self.bot.prefix
80+
81+
perm_level = next(getattr(c, 'permission_level', None) for c in cmd.checks)
82+
perm_level = f' [{perm_level}]' if perm_level is not None else ''
9083
embed = Embed(
84+
title=f'`{prefix}{cmd.signature}`{perm_level}',
9185
color=self.bot.main_color,
9286
description=cmd.help
9387
)
9488

95-
embed.title = f'`{prefix}{cmd.signature}`'
96-
9789
if not isinstance(cmd, commands.Group):
9890
return embed
9991

@@ -124,20 +116,12 @@ async def format_not_found(self, ctx, command):
124116
'a full list of commands.')
125117

126118
choices = set()
127-
# filter out hidden commands & blank cogs
128-
for i in self.bot.cogs:
129-
for cmd in self.bot.commands:
130-
if cmd.cog_name == i and not cmd.hidden and \
131-
await self.verify_checks(ctx, cmd):
132-
# as long as there's one valid cmd, add cog
133-
choices.add(i)
134-
break
135-
136-
for i in self.bot.commands:
137-
if not i.hidden and await self.verify_checks(ctx, i):
138-
choices.add(i.name)
139-
140-
closest = get_close_matches(command, choices, n=1, cutoff=0.45)
119+
120+
for name, c in self.bot.all_commands:
121+
if not c.hidden:
122+
choices.add(name)
123+
124+
closest = get_close_matches(command, choices, n=1, cutoff=0.75)
141125
if closest:
142126
# Perhaps you meant:
143127
# - `item`
@@ -157,7 +141,7 @@ async def help_(self, ctx, *, command: str = None):
157141
embeds = []
158142

159143
if cmd:
160-
help_msg = await self.format_command_help(ctx, cmd)
144+
help_msg = await self.format_command_help(cmd)
161145
if help_msg:
162146
embeds = [help_msg]
163147

@@ -876,11 +860,11 @@ async def permissions(self, ctx):
876860
levels.
877861
878862
Acceptable permission levels are:
879-
- **Owner** (absolute control over the bot)
880-
- **Administrator** (administrative powers such as setting activities)
881-
- **Moderator** (ability to block)
882-
- **Supporter** (access to core Modmail supporting functions)
883-
- **Regular** (most basic interactions such as help and about)
863+
- **Owner** [5] (absolute control over the bot)
864+
- **Administrator** [4] (administrative powers such as setting activities)
865+
- **Moderator** [3] (ability to block)
866+
- **Supporter** [2] (access to core Modmail supporting functions)
867+
- **Regular** [1] (most basic interactions such as help and about)
884868
885869
By default, owner is set to the bot owner and regular is @everyone.
886870
@@ -955,7 +939,8 @@ async def add_perms_level(self, ctx, level: str, user_or_role: Union[User, str])
955939
)
956940
return await ctx.send(embed=embed)
957941

958-
@permissions.group(name='remove', aliases=['del', 'delete', 'rm', 'revoke'])
942+
@permissions.group(name='remove', aliases=['del', 'delete', 'rm', 'revoke'],
943+
invoke_without_command=True)
959944
@checks.has_permissions(PermissionLevel.OWNER)
960945
async def remove_perms(self, ctx):
961946
"""Remove a permission to use a command or permission level."""

core/checks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ async def predicate(ctx):
3434
logger.error(error(f'You does not have permission to use this command: '
3535
f'`{ctx.command.qualified_name}` ({permission_level.name}).'))
3636
return has_perm
37+
38+
predicate.permission_level = permission_level
3739
return commands.check(predicate)
3840

3941

0 commit comments

Comments
 (0)