Skip to content

Commit 310f652

Browse files
committed
Config help
1 parent 1f8d2d0 commit 310f652

File tree

4 files changed

+438
-6
lines changed

4 files changed

+438
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ however, insignificant breaking changes does not guarantee a major version bump,
2323
- Multi-step alias, see `?help alias add`. Public beta testing, might be unstable.
2424
- Misc commands without cogs are now displayed in `?help`.
2525
- `?help` works for alias and snippets.
26+
- `?config help <config-name>` shows a help embed for the configuration.
2627

2728
### Changes
2829

@@ -35,6 +36,7 @@ however, insignificant breaking changes does not guarantee a major version bump,
3536
- `?plugin registry page-number` plugin registry can specify a page number for quick access.
3637
- A reworked interface for `?snippet` and `?alias`.
3738
- Add an `?snippet raw <name>` command for viewing the raw content of a snippet (escaped markdown).
39+
- The placeholder channel for the streaming status changed to https://www.twitch.tv/discordmodmail/.
3840

3941
### Fixes
4042

@@ -45,6 +47,7 @@ however, insignificant breaking changes does not guarantee a major version bump,
4547
- Resolves errors when message was sent by mods after thread is closed somehow.
4648
- Recipient join/leave server messages are limited to only the guild set by `GUILD_ID`.
4749
- When creating snippets and aliases, it now checks if another snippets/aliases with the same name exists.
50+
- Was looking for `config.json` in the wrong directory.
4851

4952
### Internal
5053

cogs/utility.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,14 @@ async def config(self, ctx):
733733
Type `{prefix}config options` to view a list
734734
of valid configuration variables.
735735
736+
Type `{prefix}config help config-name` for info
737+
on a config.
738+
736739
To set a configuration variable:
737-
- `{prefix}config set varname value here`
740+
- `{prefix}config set config-name value here`
738741
739742
To remove a configuration variable:
740-
- `{prefix}config remove varname`
743+
- `{prefix}config remove config-name`
741744
"""
742745
await ctx.send_help(ctx.command)
743746

@@ -849,6 +852,52 @@ async def config_get(self, ctx, key: str.lower = None):
849852

850853
return await ctx.send(embed=embed)
851854

855+
@config.command(name="help", aliases=["info"])
856+
@checks.has_permissions(PermissionLevel.OWNER)
857+
async def config_help(self, ctx, key: str.lower):
858+
"""
859+
Show information on a specified configuration.
860+
"""
861+
if key not in self.bot.config.public_keys:
862+
embed = Embed(
863+
title="Error",
864+
color=Color.red(),
865+
description=f"`{key}` is an invalid key.",
866+
)
867+
return await ctx.send(embed=embed)
868+
869+
config_help = self.bot.config.config_help
870+
info = config_help.get(key)
871+
872+
if info is None:
873+
embed = Embed(
874+
title="Error",
875+
color=Color.red(),
876+
description=f"No help details found for `{key}`.",
877+
)
878+
return await ctx.send(embed=embed)
879+
880+
def fmt(val):
881+
return val.format(prefix=self.bot.prefix, bot=self.bot)
882+
883+
embed = Embed(
884+
title=f"Configuration description on {key}:",
885+
color=self.bot.main_color
886+
)
887+
embed.add_field(name='Default:', value=fmt(info['default']), inline=False)
888+
embed.add_field(name='Information:', value=fmt(info['description']), inline=False)
889+
example_text = ''
890+
for example in info['examples']:
891+
example_text += f'- {fmt(example)}\n'
892+
embed.add_field(name='Example(s):', value=example_text, inline=False)
893+
894+
note_text = ''
895+
for note in info['notes']:
896+
note_text += f'- {fmt(note)}\n'
897+
if note_text:
898+
embed.add_field(name='Notes(s):', value=note_text, inline=False)
899+
return await ctx.send(embed=embed)
900+
852901
@commands.group(aliases=["aliases"], invoke_without_command=True)
853902
@checks.has_permissions(PermissionLevel.MODERATOR)
854903
async def alias(self, ctx, *, name: str.lower = None):

core/config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ConfigManager:
2424

2525
public_keys = {
2626
# activity
27-
"twitch_url": "https://www.twitch.tv/discord-modmail/",
27+
"twitch_url": "https://www.twitch.tv/discordmodmail/",
2828
# bot settings
2929
"main_category_id": None,
3030
"prefix": "?",
@@ -55,8 +55,8 @@ class ConfigManager:
5555
"thread_self_close_response": "You have closed this Modmail thread.",
5656
# moderation
5757
"recipient_color": str(discord.Color.gold()),
58-
"mod_tag": None,
5958
"mod_color": str(discord.Color.green()),
59+
"mod_tag": None,
6060
# anonymous message
6161
"anon_username": None,
6262
"anon_avatar_url": None,
@@ -117,6 +117,7 @@ def __init__(self, bot):
117117
self.bot = bot
118118
self._cache = {}
119119
self.ready_event = asyncio.Event()
120+
self.config_help = {}
120121

121122
def __repr__(self):
122123
return repr(self._cache)
@@ -129,7 +130,7 @@ def populate_cache(self) -> dict:
129130
{k.lower(): v for k, v in os.environ.items() if k.lower() in self.all_keys}
130131
)
131132
configjson = os.path.join(
132-
os.path.dirname(os.path.abspath(__file__)), "config.json"
133+
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config.json"
133134
)
134135
if os.path.exists(configjson):
135136
logger.debug("Loading envs from config.json.")
@@ -147,8 +148,13 @@ def populate_cache(self) -> dict:
147148
logger.critical(
148149
"Failed to load config.json env values.", exc_info=True
149150
)
150-
151151
self._cache = data
152+
153+
confighelpjson = os.path.join(
154+
os.path.dirname(os.path.abspath(__file__)), "config_help.json"
155+
)
156+
with open(confighelpjson, "r") as f:
157+
self.config_help = json.load(f)
152158
return self._cache
153159

154160
async def clean_data(self, key: str, val: typing.Any) -> typing.Tuple[str, str]:

0 commit comments

Comments
 (0)