Skip to content

Commit 030f7b1

Browse files
committed
strtobool support enable and disable, perhaps you meant for config help
1 parent 27bbd71 commit 030f7b1

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.
77
however, insignificant breaking changes does not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319).
88

99

10+
# v3.3.1-dev0
11+
12+
### Added
13+
14+
- "enable" and "disable" support for yes or no config vars.
15+
- Added "perhaps you meant" section to `?config help`.
16+
1017
# v3.3.0
1118

1219

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.3.0"
1+
__version__ = "3.3.1-dev0"
22

33
import asyncio
44
import logging

cogs/utility.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,19 @@ async def config_help(self, ctx, key: str.lower = None):
848848
if key is not None and not (
849849
key in self.bot.config.public_keys or key in self.bot.config.protected_keys
850850
):
851+
closest = get_close_matches(
852+
key, {**self.bot.config.public_keys, **self.bot.config.protected_keys}
853+
)
851854
embed = discord.Embed(
852855
title="Error",
853856
color=self.bot.error_color,
854857
description=f"`{key}` is an invalid key.",
855858
)
859+
if closest:
860+
embed.add_field(
861+
name=f"Perhaps you meant:",
862+
value="\n".join(f"`{x}`" for x in closest),
863+
)
856864
return await ctx.send(embed=embed)
857865

858866
config_help = self.bot.config.config_help

core/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
def strtobool(val):
1515
if isinstance(val, bool):
1616
return val
17-
return _stb(str(val))
17+
try:
18+
return _stb(str(val))
19+
except ValueError:
20+
val = val.lower()
21+
if val == "enable":
22+
return 1
23+
elif val == "disable":
24+
return 0
25+
raise
1826

1927

2028
class User(commands.IDConverter):

0 commit comments

Comments
 (0)