docs (config): Add more documentation.
Write `config` command docs. Extend `config` header and add tutorial link. Allow moderators to read settings (but not configure them). Change `config help` to `config info`.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import discord
|
import discord
|
||||||
|
from cmdClient.lib import SafeCancellation
|
||||||
|
|
||||||
from wards import guild_admin
|
from wards import guild_admin, guild_moderator
|
||||||
from settings import UserInputError, GuildSettings
|
from settings import UserInputError, GuildSettings
|
||||||
|
|
||||||
from utils.lib import prop_tabulate
|
from utils.lib import prop_tabulate
|
||||||
@@ -26,12 +27,40 @@ descriptions = {
|
|||||||
desc="View and modify the server settings.",
|
desc="View and modify the server settings.",
|
||||||
flags=('add', 'remove'),
|
flags=('add', 'remove'),
|
||||||
group="Guild Configuration")
|
group="Guild Configuration")
|
||||||
@guild_admin()
|
@guild_moderator()
|
||||||
async def cmd_config(ctx, flags):
|
async def cmd_config(ctx, flags):
|
||||||
|
"""
|
||||||
|
Usage``:
|
||||||
|
{prefix}config
|
||||||
|
{prefix}config info
|
||||||
|
{prefix}config <setting>
|
||||||
|
{prefix}config <setting> <value>
|
||||||
|
Description:
|
||||||
|
Display the server configuration panel, and view/modify the server settings.
|
||||||
|
|
||||||
|
Use `{prefix}config` to see the settings with their current values, or `{prefix}config info` to \
|
||||||
|
show brief descriptions instead.
|
||||||
|
Use `{prefix}config <setting>` (e.g. `{prefix}config event_log`) to view a more detailed description for each setting, \
|
||||||
|
including the possible values.
|
||||||
|
Finally, use `{prefix}config <setting> <value>` to set the setting to the given value.
|
||||||
|
To unset a setting, or set it to the default, use `{prefix}config <setting> None`.
|
||||||
|
|
||||||
|
Additional usage for settings which accept a list of values:
|
||||||
|
`{prefix}config <setting> <value1>, <value2>, ...`
|
||||||
|
`{prefix}config <setting> --add <value1>, <value2>, ...`
|
||||||
|
`{prefix}config <setting> --remove <value1>, <value2>, ...`
|
||||||
|
Note that the first form *overwrites* the setting completely,\
|
||||||
|
while the second two will only *add* and *remove* values, respectively.
|
||||||
|
Examples``:
|
||||||
|
{prefix}config event_log
|
||||||
|
{prefix}config event_log {ctx.ch.name}
|
||||||
|
{prefix}config autoroles Member, Level 0, Level 10
|
||||||
|
{prefix}config autoroles --remove Level 10
|
||||||
|
"""
|
||||||
# Cache and map some info for faster access
|
# Cache and map some info for faster access
|
||||||
setting_displaynames = {setting.display_name.lower(): setting for setting in GuildSettings.settings.values()}
|
setting_displaynames = {setting.display_name.lower(): setting for setting in GuildSettings.settings.values()}
|
||||||
|
|
||||||
if not ctx.args or ctx.args.lower() == 'help':
|
if not ctx.args or ctx.args.lower() in ('info', 'help'):
|
||||||
# Fill the setting cats
|
# Fill the setting cats
|
||||||
cats = {}
|
cats = {}
|
||||||
for setting in GuildSettings.settings.values():
|
for setting in GuildSettings.settings.values():
|
||||||
@@ -60,8 +89,14 @@ async def cmd_config(ctx, flags):
|
|||||||
colour=discord.Colour.orange(),
|
colour=discord.Colour.orange(),
|
||||||
title=page_name,
|
title=page_name,
|
||||||
description=(
|
description=(
|
||||||
"View brief setting descriptions with `{prefix}config help`.\n"
|
"View brief setting descriptions with `{prefix}config info`.\n"
|
||||||
"See `{prefix}help config` for more general usage.".format(prefix=ctx.best_prefix)
|
"Use e.g. `{prefix}config event_log` to see more details.\n"
|
||||||
|
"Modify a setting with e.g. `{prefix}config event_log {ctx.ch.name}`.\n"
|
||||||
|
"See the [Online Tutorial]({tutorial}) for a complete setup guide.".format(
|
||||||
|
prefix=ctx.best_prefix,
|
||||||
|
ctx=ctx,
|
||||||
|
tutorial="https://discord.studylions.com/tutorial"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for name, value in page.items():
|
for name, value in page.items():
|
||||||
@@ -71,7 +106,7 @@ async def cmd_config(ctx, flags):
|
|||||||
|
|
||||||
if len(pages) > 1:
|
if len(pages) > 1:
|
||||||
[
|
[
|
||||||
embed.set_footer(text="Page {}/{}".format(i+1, len(pages)))
|
embed.set_footer(text="Page {} of {}".format(i+1, len(pages)))
|
||||||
for i, embed in enumerate(pages)
|
for i, embed in enumerate(pages)
|
||||||
]
|
]
|
||||||
await ctx.pager(pages)
|
await ctx.pager(pages)
|
||||||
@@ -98,9 +133,12 @@ async def cmd_config(ctx, flags):
|
|||||||
await setting.get(ctx.guild.id).widget(ctx, flags=flags)
|
await setting.get(ctx.guild.id).widget(ctx, flags=flags)
|
||||||
else:
|
else:
|
||||||
# config <setting> <value>
|
# config <setting> <value>
|
||||||
|
# Ignoring the write ward currently and just enforcing admin
|
||||||
# Check the write ward
|
# Check the write ward
|
||||||
if not await setting.write_ward.run(ctx):
|
# if not await setting.write_ward.run(ctx):
|
||||||
await ctx.error_reply(setting.write_ward.msg)
|
# raise SafeCancellation(setting.write_ward.msg)
|
||||||
|
if not await guild_admin.run(ctx):
|
||||||
|
raise SafeCancellation("You need to be a server admin to modify settings!")
|
||||||
|
|
||||||
# Attempt to set config setting
|
# Attempt to set config setting
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user