Skip to content

Commit 0032a9d

Browse files
committed
Fix override
1 parent 259ba09 commit 0032a9d

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ however, insignificant breaking changes does not guarantee a major version bump,
2222
### Internal
2323

2424
- Use regex to parse Changes, Added, Fixed, etc and description.
25+
- Adds `PermissionLevel.INVALID` when commands doesn't have a permission level.
2526

2627
# v3.1.1
2728

bot.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
except ImportError:
3030
pass
3131

32+
from core import checks
3233
from core.clients import ApiClient, PluginDatabaseClient
3334
from core.config import ConfigManager
3435
from core.utils import human_join, strtobool, parse_alias
@@ -840,6 +841,17 @@ async def process_commands(self, message):
840841
ctxs = await self.get_contexts(message)
841842
for ctx in ctxs:
842843
if ctx.command:
844+
if not any(
845+
1
846+
for check in ctx.command.checks
847+
if hasattr(check, "permission_level")
848+
):
849+
logger.debug(
850+
"Command %s has no permissions check, adding invalid level.",
851+
ctx.command.qualified_name,
852+
)
853+
checks.has_permissions(PermissionLevel.INVALID)(ctx.command)
854+
843855
await self.invoke(ctx)
844856
continue
845857

@@ -1074,7 +1086,7 @@ async def on_command_error(self, context, exception):
10741086
color=discord.Color.red(), description=check.fail_msg
10751087
)
10761088
)
1077-
if hasattr(check, 'permission_level'):
1089+
if hasattr(check, "permission_level"):
10781090
corrected_permission_level = self.command_perm(
10791091
context.command.qualified_name
10801092
)

cogs/utility.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ async def set_presence(
646646
@tasks.loop(minutes=45)
647647
async def loop_presence(self):
648648
"""Set presence to the configured value every 45 minutes."""
649+
# TODO: Does this even work?
649650
presence = await self.set_presence()
650651
logger.debug(f'{presence["activity"][1]} {presence["status"][1]}')
651652

@@ -1295,10 +1296,6 @@ async def permissions_override(
12951296
command.qualified_name
12961297
] = level.name
12971298

1298-
if not any(check for check in command.checks if hasattr(check, "permission_level")):
1299-
logger.debug('Command %s has no permissions check, adding invalid.', command.qualified_name)
1300-
checks.has_permissions(PermissionLevel.INVALID)(command)
1301-
13021299
await self.bot.config.update()
13031300
embed = Embed(
13041301
title="Success",
@@ -1618,25 +1615,37 @@ async def permissions_get(
16181615
for command in self.bot.walk_commands():
16191616
if command not in done:
16201617
done.add(command)
1621-
level = self.bot.config["override_command_level"].get(command.qualified_name)
1618+
level = self.bot.config["override_command_level"].get(
1619+
command.qualified_name
1620+
)
16221621
if level is not None:
16231622
overrides[command.qualified_name] = level
16241623

16251624
embeds = []
16261625
if not overrides:
1627-
embeds.append(Embed(
1628-
title="Permission Overrides",
1629-
description="You don't have any command level overrides at the moment.",
1630-
color=Color.red()
1631-
))
1626+
embeds.append(
1627+
Embed(
1628+
title="Permission Overrides",
1629+
description="You don't have any command level overrides at the moment.",
1630+
color=Color.red(),
1631+
)
1632+
)
16321633
else:
1633-
for items in zip_longest(*(iter(sorted(overrides.items())),) * 15):
1634+
for items in zip_longest(
1635+
*(iter(sorted(overrides.items())),) * 15
1636+
):
16341637
description = "\n".join(
16351638
": ".join((f"`{name}`", level))
1636-
for name, level in takewhile(lambda x: x is not None, items)
1639+
for name, level in takewhile(
1640+
lambda x: x is not None, items
1641+
)
1642+
)
1643+
embed = Embed(
1644+
color=self.bot.main_color, description=description
1645+
)
1646+
embed.set_author(
1647+
name="Permission Overrides", icon_url=ctx.guild.icon_url
16371648
)
1638-
embed = Embed(color=self.bot.main_color, description=description)
1639-
embed.set_author(name="Permission Overrides", icon_url=ctx.guild.icon_url)
16401649
embeds.append(embed)
16411650

16421651
session = EmbedPaginatorSession(ctx, *embeds)

core/checks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
logger = logging.getLogger("Modmail")
88

99

10-
def has_permissions_predicate(permission_level: PermissionLevel = PermissionLevel.REGULAR):
10+
def has_permissions_predicate(
11+
permission_level: PermissionLevel = PermissionLevel.REGULAR
12+
):
1113
async def predicate(ctx):
1214
return await check_permissions(ctx, ctx.command.qualified_name)
1315

0 commit comments

Comments
 (0)