Skip to content

Commit 2a0e93e

Browse files
committed
bugfixing and optimisations
1 parent 99f5175 commit 2a0e93e

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
77
however, insignificant breaking changes do not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319). If you're a plugin developer, note the "BREAKING" section.
88

9+
# v3.7.8
10+
11+
### Fixed
12+
- Permission levels were not respected
13+
- `perms remove` was not working
14+
- `logs` and `block` would not recognise users in a seperate server setup.
15+
16+
### Internal
17+
- Optimised `perms get`, bot should respond faster now
18+
919
# v3.7.7
1020

1121
### Added

bot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.7.7"
1+
__version__ = "3.7.8"
22

33

44
import asyncio
@@ -1002,6 +1002,11 @@ async def update_perms(
10021002
else:
10031003
if value in permissions[name]:
10041004
permissions[name].remove(value)
1005+
1006+
if isinstance(name, PermissionLevel):
1007+
self.config["level_permissions"] = permissions
1008+
else:
1009+
self.config["command_permissions"] = permissions
10051010
logger.info("Updating permissions for %s, %s (add=%s).", name, value, add)
10061011
await self.config.update()
10071012

@@ -1355,6 +1360,7 @@ async def on_error(self, event_method, *args, **kwargs):
13551360

13561361
async def on_command_error(self, context, exception):
13571362
if isinstance(exception, commands.BadUnionArgument):
1363+
logger.error("Expected exception:", exc_info=exception)
13581364
msg = "Could not find the specified " + human_join(
13591365
[c.__name__ for c in exception.converters]
13601366
)

cogs/utility.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,23 +1496,25 @@ async def permissions_get(
14961496
"""
14971497

14981498
if name is None and user_or_role not in {"command", "level", "override"}:
1499-
value = self._verify_user_or_role(user_or_role)
1499+
value = str(self._verify_user_or_role(user_or_role))
15001500

15011501
cmds = []
15021502
levels = []
15031503

15041504
done = set()
1505+
command_permissions = self.bot.config["command_permissions"]
1506+
level_permissions = self.bot.config["level_permissions"]
15051507
for command in self.bot.walk_commands():
15061508
if command not in done:
15071509
done.add(command)
1508-
permissions = self.bot.config["command_permissions"].get(
1510+
permissions = command_permissions.get(
15091511
command.qualified_name, []
15101512
)
15111513
if value in permissions:
15121514
cmds.append(command.qualified_name)
15131515

15141516
for level in PermissionLevel:
1515-
permissions = self.bot.config["level_permissions"].get(level.name, [])
1517+
permissions = level_permissions.get(level.name, [])
15161518
if value in permissions:
15171519
levels.append(level.name)
15181520

core/checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def check_permissions(ctx, command_name) -> bool:
6262
if command_name in command_permissions:
6363
# -1 is for @everyone
6464
return -1 in command_permissions[command_name] or any(
65-
check.id in command_permissions[command_name] for check in checkables
65+
str(check.id) in command_permissions[command_name] for check in checkables
6666
)
6767

6868
level_permissions = ctx.bot.config["level_permissions"]
@@ -71,7 +71,7 @@ async def check_permissions(ctx, command_name) -> bool:
7171
if level >= permission_level and level.name in level_permissions:
7272
# -1 is for @everyone
7373
if -1 in level_permissions[level.name] or any(
74-
check.id in level_permissions[level.name] for check in checkables
74+
str(check.id) in level_permissions[level.name] for check in checkables
7575
):
7676
return True
7777
return False

core/config.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from core._color_data import ALL_COLORS
1515
from core.models import DMDisabled, InvalidConfigError, Default, getLogger
1616
from core.time import UserFriendlyTimeSync
17-
from core.utils import strtobool
17+
from core.utils import strtobool, tryint
1818

1919
logger = getLogger(__name__)
2020
load_dotenv()
@@ -175,6 +175,11 @@ class ConfigManager:
175175
"activity_type": discord.ActivityType,
176176
}
177177

178+
force_str = {
179+
"command_permissions",
180+
"level_permissions"
181+
}
182+
178183
defaults = {**public_keys, **private_keys, **protected_keys}
179184
all_keys = set(defaults.keys())
180185

@@ -245,18 +250,19 @@ def __setitem__(self, key: str, item: typing.Any) -> None:
245250
self._cache[key] = item
246251

247252
def __getitem__(self, key: str) -> typing.Any:
248-
key = key.lower()
249-
if key not in self.all_keys:
250-
raise InvalidConfigError(f'Configuration "{key}" is invalid.')
251-
if key not in self._cache:
252-
self._cache[key] = deepcopy(self.defaults[key])
253-
return self._cache[key]
253+
# make use of the custom methods in func:get:
254+
return self.get(key)
254255

255256
def __delitem__(self, key: str) -> None:
256257
return self.remove(key)
257258

258259
def get(self, key: str, convert=True) -> typing.Any:
259-
value = self.__getitem__(key)
260+
key = key.lower()
261+
if key not in self.all_keys:
262+
raise InvalidConfigError(f'Configuration "{key}" is invalid.')
263+
if key not in self._cache:
264+
self._cache[key] = deepcopy(self.defaults[key])
265+
value = self._cache[key]
260266

261267
if not convert:
262268
return value
@@ -295,6 +301,29 @@ def get(self, key: str, convert=True) -> typing.Any:
295301
logger.warning("Invalid %s %s.", key, value)
296302
value = self.remove(key)
297303

304+
elif key in self.force_str:
305+
# Temporary: as we saved in int previously, leading to int32 overflow,
306+
# this is transitioning IDs to strings
307+
new_value = {}
308+
changed = False
309+
for k, v in value.items():
310+
new_v = v
311+
if isinstance(v, list):
312+
new_v = []
313+
for n in v:
314+
print('x', n, v)
315+
if n != -1 and not isinstance(n, str):
316+
changed = True
317+
n = str(n)
318+
new_v.append(n)
319+
new_value[k] = new_v
320+
321+
if changed:
322+
# transition the database as well
323+
self.set(key, new_value)
324+
325+
value = new_value
326+
298327
return value
299328

300329
def set(self, key: str, item: typing.Any, convert=True) -> None:

core/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class User(commands.IDConverter):
5656
# noinspection PyCallByClass,PyTypeChecker
5757
async def convert(self, ctx, argument):
5858
try:
59-
return await commands.MemberConverter.convert(self, ctx, argument)
59+
return await commands.MemberConverter().convert(ctx, argument)
6060
except commands.BadArgument:
6161
pass
6262
try:
63-
return await commands.UserConverter.convert(self, ctx, argument)
63+
return await commands.UserConverter().convert(ctx, argument)
6464
except commands.BadArgument:
6565
pass
6666
match = self._get_id_match(argument)

0 commit comments

Comments
 (0)