Skip to content

Commit 9460947

Browse files
committed
Added lower and upper limits to config
1 parent 3ae08e9 commit 9460947

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

core/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ class ConfigManager:
238238
"activity_type": discord.ActivityType,
239239
}
240240

241+
limits = {
242+
"confirm_thread_creation_timeout": (20, 200),
243+
}
244+
241245
force_str = {"command_permissions", "level_permissions"}
242246

243247
defaults = {**public_keys, **private_keys, **protected_keys}
@@ -297,7 +301,15 @@ def __setitem__(self, key: str, item: typing.Any) -> None:
297301
logger.info("Setting %s.", key)
298302
if key not in self.all_keys:
299303
raise InvalidConfigError(f'Configuration "{key}" is invalid.')
304+
old_value = self._cache.get(key)
300305
self._cache[key] = item
306+
if key in self.limits:
307+
lower, upper = self.limits[key]
308+
if not lower <= self.get(key) <= upper:
309+
self._cache[key] = old_value
310+
raise InvalidConfigError(
311+
f"Configuration {key} must be between {lower} and {upper} inclusive."
312+
)
301313

302314
def __getitem__(self, key: str) -> typing.Any:
303315
# make use of the custom methods in func:get:

core/config_help.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@
10051005
},
10061006
"confirm_thread_creation_timeout": {
10071007
"default": "20",
1008-
"description": "How long the user has to confirm thread creation before the request times out",
1008+
"description": "How long the user has to confirm thread creation before the request times out. Limited between 1 second and 120 seconds",
10091009
"examples":[
10101010
"`{prefix}config set confirm_thread_creation_timeout 30`"
10111011
],

0 commit comments

Comments
 (0)