Add settings view commands (#4041)

Any group which sent help + settings views has had the settings view
  split into a seperate command. This ensures that custom help behavior
  does not interfere with settings views.
This commit is contained in:
Michael H 2020-07-06 18:53:41 -04:00 committed by GitHub
parent 2cf7a1f80d
commit 60df447550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 200 additions and 177 deletions

View File

@ -43,10 +43,13 @@ class Bank(commands.Cog):
@is_owner_if_bank_global() @is_owner_if_bank_global()
@checks.guildowner_or_permissions(administrator=True) @checks.guildowner_or_permissions(administrator=True)
@commands.group(autohelp=True) @commands.group()
async def bankset(self, ctx: commands.Context): async def bankset(self, ctx: commands.Context):
"""Base command for bank settings.""" """Base command for bank settings."""
if ctx.invoked_subcommand is None:
@bankset.command(name="showsettings")
async def bankset_showsettings(self, ctx: commands.Context):
"""Show the current bank settings."""
cur_setting = await bank.is_global() cur_setting = await bank.is_global()
if cur_setting: if cur_setting:
group = bank._config group = bank._config

View File

@ -655,12 +655,17 @@ class Economy(commands.Cog):
@commands.group() @commands.group()
async def economyset(self, ctx: commands.Context): async def economyset(self, ctx: commands.Context):
"""Manage Economy settings.""" """Manage Economy settings."""
@economyset.command(name="showsettings")
async def economyset_showsettings(self, ctx: commands.Context):
"""
Shows the current economy settings
"""
guild = ctx.guild guild = ctx.guild
if ctx.invoked_subcommand is None:
if await bank.is_global(): if await bank.is_global():
conf = self.config conf = self.config
else: else:
conf = self.config.guild(ctx.guild) conf = self.config.guild(guild)
await ctx.send( await ctx.send(
box( box(
_( _(

View File

@ -18,9 +18,11 @@ class ModSettings(MixinMeta):
@checks.guildowner_or_permissions(administrator=True) @checks.guildowner_or_permissions(administrator=True)
async def modset(self, ctx: commands.Context): async def modset(self, ctx: commands.Context):
"""Manage server administration settings.""" """Manage server administration settings."""
if ctx.invoked_subcommand is None:
@modset.command(name="showsettings")
async def modset_showsettings(self, ctx: commands.Context):
"""Show the current server administration settings."""
guild = ctx.guild guild = ctx.guild
# Display current settings
data = await self.config.guild(guild).all() data = await self.config.guild(guild).all()
delete_repeats = data["delete_repeats"] delete_repeats = data["delete_repeats"]
ban_mention_spam = data["ban_mention_spam"] ban_mention_spam = data["ban_mention_spam"]
@ -55,9 +57,9 @@ class ModSettings(MixinMeta):
yes_or_no=_("Yes") if dm_on_kickban else _("No") yes_or_no=_("Yes") if dm_on_kickban else _("No")
) )
if default_days: if default_days:
msg += _( msg += _("Default message history delete on ban: Previous {num_days} days\n").format(
"Default message history delete on ban: Previous {num_days} days\n" num_days=default_days
).format(num_days=default_days) )
else: else:
msg += _("Default message history delete on ban: Don't delete any\n") msg += _("Default message history delete on ban: Don't delete any\n")
await ctx.send(box(msg)) await ctx.send(box(msg))

View File

@ -224,8 +224,10 @@ class Permissions(commands.Cog):
@permissions.group(name="acl", aliases=["yaml"]) @permissions.group(name="acl", aliases=["yaml"])
async def permissions_acl(self, ctx: commands.Context): async def permissions_acl(self, ctx: commands.Context):
"""Manage permissions with YAML files.""" """Manage permissions with YAML files."""
if ctx.invoked_subcommand is None or ctx.invoked_subcommand == self.permissions_acl:
# Send a little guide on YAML formatting @permissions_acl.command(name="yamlexample")
async def permissions_acl_yaml_example(self, ctx: commands.Context):
"""Sends an example of the yaml layout for permissions"""
await ctx.send( await ctx.send(
_("Example YAML for setting rules:\n") _("Example YAML for setting rules:\n")
+ box( + box(

View File

@ -61,7 +61,10 @@ class Trivia(commands.Cog):
@checks.mod_or_permissions(administrator=True) @checks.mod_or_permissions(administrator=True)
async def triviaset(self, ctx: commands.Context): async def triviaset(self, ctx: commands.Context):
"""Manage Trivia settings.""" """Manage Trivia settings."""
if ctx.invoked_subcommand is None:
@triviaset.command(name="showsettings")
async def triviaset_showsettings(self, ctx: commands.Context):
"""Show the current trivia settings."""
settings = self.config.guild(ctx.guild) settings = self.config.guild(ctx.guild)
settings_dict = await settings.all() settings_dict = await settings.all()
msg = box( msg = box(

View File

@ -453,7 +453,10 @@ class Core(commands.Cog, CoreLogic):
commands that support it). The default is to commands that support it). The default is to
use embeds. use embeds.
""" """
if ctx.invoked_subcommand is None:
@embedset.command(name="showsettings")
async def embedset_showsettings(self, ctx: commands.Context):
"""Show the current embed settings."""
text = _("Embed settings:\n\n") text = _("Embed settings:\n\n")
global_default = await self.bot._config.embeds() global_default = await self.bot._config.embeds()
text += _("Global default: {}\n").format(global_default) text += _("Global default: {}\n").format(global_default)
@ -939,15 +942,18 @@ class Core(commands.Cog, CoreLogic):
@commands.group(name="set") @commands.group(name="set")
async def _set(self, ctx: commands.Context): async def _set(self, ctx: commands.Context):
"""Changes [botname]'s settings.""" """Changes [botname]'s settings."""
if ctx.invoked_subcommand is None:
@_set.command("showsettings")
async def set_showsettings(self, ctx: commands.Context):
"""
Show the current settings for [botname].
"""
if ctx.guild: if ctx.guild:
guild_data = await ctx.bot._config.guild(ctx.guild).all() guild_data = await ctx.bot._config.guild(ctx.guild).all()
guild = ctx.guild guild = ctx.guild
admin_role_ids = guild_data["admin_role"] admin_role_ids = guild_data["admin_role"]
admin_role_names = [r.name for r in guild.roles if r.id in admin_role_ids] admin_role_names = [r.name for r in guild.roles if r.id in admin_role_ids]
admin_roles_str = ( admin_roles_str = humanize_list(admin_role_names) if admin_role_names else "Not Set."
humanize_list(admin_role_names) if admin_role_names else "Not Set."
)
mod_role_ids = guild_data["mod_role"] mod_role_ids = guild_data["mod_role"]
mod_role_names = [r.name for r in guild.roles if r.id in mod_role_ids] mod_role_names = [r.name for r in guild.roles if r.id in mod_role_ids]
mod_roles_str = humanize_list(mod_role_names) if mod_role_names else "Not Set." mod_roles_str = humanize_list(mod_role_names) if mod_role_names else "Not Set."
@ -2550,7 +2556,12 @@ class Core(commands.Cog, CoreLogic):
@checks.admin_or_permissions(manage_channels=True) @checks.admin_or_permissions(manage_channels=True)
async def ignore(self, ctx: commands.Context): async def ignore(self, ctx: commands.Context):
"""Add servers or channels to the ignore list.""" """Add servers or channels to the ignore list."""
if ctx.invoked_subcommand is None:
@ignore.command(name="list")
async def ignore_list(self, ctx: commands.Context):
"""
List the currently ignored servers and channels
"""
for page in pagify(await self.count_ignored(ctx)): for page in pagify(await self.count_ignored(ctx)):
await ctx.maybe_send_embed(page) await ctx.maybe_send_embed(page)
@ -2588,9 +2599,6 @@ class Core(commands.Cog, CoreLogic):
@checks.admin_or_permissions(manage_channels=True) @checks.admin_or_permissions(manage_channels=True)
async def unignore(self, ctx: commands.Context): async def unignore(self, ctx: commands.Context):
"""Remove servers or channels from the ignore list.""" """Remove servers or channels from the ignore list."""
if ctx.invoked_subcommand is None:
for page in pagify(await self.count_ignored(ctx)):
await ctx.maybe_send_embed(page)
@unignore.command(name="channel") @unignore.command(name="channel")
async def unignore_channel( async def unignore_channel(