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,36 +43,39 @@ 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:
cur_setting = await bank.is_global()
if cur_setting:
group = bank._config
else:
if not ctx.guild:
return
group = bank._config.guild(ctx.guild)
group_data = await group.all()
bank_name = group_data["bank_name"]
bank_scope = _("Global") if cur_setting else _("Server")
currency_name = group_data["currency"]
default_balance = group_data["default_balance"]
max_balance = group_data["max_balance"]
settings = _( @bankset.command(name="showsettings")
"Bank settings:\n\nBank name: {bank_name}\nBank scope: {bank_scope}\n" async def bankset_showsettings(self, ctx: commands.Context):
"Currency: {currency_name}\nDefault balance: {default_balance}\n" """Show the current bank settings."""
"Maximum allowed balance: {maximum_bal}\n" cur_setting = await bank.is_global()
).format( if cur_setting:
bank_name=bank_name, group = bank._config
bank_scope=bank_scope, else:
currency_name=currency_name, if not ctx.guild:
default_balance=humanize_number(default_balance), return
maximum_bal=humanize_number(max_balance), group = bank._config.guild(ctx.guild)
) group_data = await group.all()
await ctx.send(box(settings)) bank_name = group_data["bank_name"]
bank_scope = _("Global") if cur_setting else _("Server")
currency_name = group_data["currency"]
default_balance = group_data["default_balance"]
max_balance = group_data["max_balance"]
settings = _(
"Bank settings:\n\nBank name: {bank_name}\nBank scope: {bank_scope}\n"
"Currency: {currency_name}\nDefault balance: {default_balance}\n"
"Maximum allowed balance: {maximum_bal}\n"
).format(
bank_name=bank_name,
bank_scope=bank_scope,
currency_name=currency_name,
default_balance=humanize_number(default_balance),
maximum_bal=humanize_number(max_balance),
)
await ctx.send(box(settings))
@bankset.command(name="toggleglobal") @bankset.command(name="toggleglobal")
@checks.is_owner() @checks.is_owner()

View File

@ -655,34 +655,39 @@ 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(guild)
conf = self.config.guild(ctx.guild) await ctx.send(
await ctx.send( box(
box( _(
_( "----Economy Settings---\n"
"----Economy Settings---\n" "Minimum slot bid: {slot_min}\n"
"Minimum slot bid: {slot_min}\n" "Maximum slot bid: {slot_max}\n"
"Maximum slot bid: {slot_max}\n" "Slot cooldown: {slot_time}\n"
"Slot cooldown: {slot_time}\n" "Payday amount: {payday_amount}\n"
"Payday amount: {payday_amount}\n" "Payday cooldown: {payday_time}\n"
"Payday cooldown: {payday_time}\n" "Amount given at account registration: {register_amount}\n"
"Amount given at account registration: {register_amount}\n" "Maximum allowed balance: {maximum_bal}"
"Maximum allowed balance: {maximum_bal}" ).format(
).format( slot_min=humanize_number(await conf.SLOT_MIN()),
slot_min=humanize_number(await conf.SLOT_MIN()), slot_max=humanize_number(await conf.SLOT_MAX()),
slot_max=humanize_number(await conf.SLOT_MAX()), slot_time=humanize_number(await conf.SLOT_TIME()),
slot_time=humanize_number(await conf.SLOT_TIME()), payday_time=humanize_number(await conf.PAYDAY_TIME()),
payday_time=humanize_number(await conf.PAYDAY_TIME()), payday_amount=humanize_number(await conf.PAYDAY_CREDITS()),
payday_amount=humanize_number(await conf.PAYDAY_CREDITS()), register_amount=humanize_number(await bank.get_default_balance(guild)),
register_amount=humanize_number(await bank.get_default_balance(guild)), maximum_bal=humanize_number(await bank.get_max_balance(guild)),
maximum_bal=humanize_number(await bank.get_max_balance(guild)),
)
) )
) )
)
@economyset.command() @economyset.command()
async def slotmin(self, ctx: commands.Context, bid: int): async def slotmin(self, ctx: commands.Context, bid: int):

View File

@ -18,49 +18,51 @@ 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:
guild = ctx.guild @modset.command(name="showsettings")
# Display current settings async def modset_showsettings(self, ctx: commands.Context):
data = await self.config.guild(guild).all() """Show the current server administration settings."""
delete_repeats = data["delete_repeats"] guild = ctx.guild
ban_mention_spam = data["ban_mention_spam"] data = await self.config.guild(guild).all()
respect_hierarchy = data["respect_hierarchy"] delete_repeats = data["delete_repeats"]
delete_delay = data["delete_delay"] ban_mention_spam = data["ban_mention_spam"]
reinvite_on_unban = data["reinvite_on_unban"] respect_hierarchy = data["respect_hierarchy"]
dm_on_kickban = data["dm_on_kickban"] delete_delay = data["delete_delay"]
default_days = data["default_days"] reinvite_on_unban = data["reinvite_on_unban"]
msg = "" dm_on_kickban = data["dm_on_kickban"]
msg += _("Delete repeats: {num_repeats}\n").format( default_days = data["default_days"]
num_repeats=_("after {num} repeats").format(num=delete_repeats) msg = ""
if delete_repeats != -1 msg += _("Delete repeats: {num_repeats}\n").format(
else _("No") num_repeats=_("after {num} repeats").format(num=delete_repeats)
if delete_repeats != -1
else _("No")
)
msg += _("Ban mention spam: {num_mentions}\n").format(
num_mentions=_("{num} mentions").format(num=ban_mention_spam)
if ban_mention_spam
else _("No")
)
msg += _("Respects hierarchy: {yes_or_no}\n").format(
yes_or_no=_("Yes") if respect_hierarchy else _("No")
)
msg += _("Delete delay: {num_seconds}\n").format(
num_seconds=_("{num} seconds").format(num=delete_delay)
if delete_delay != -1
else _("None")
)
msg += _("Reinvite on unban: {yes_or_no}\n").format(
yes_or_no=_("Yes") if reinvite_on_unban else _("No")
)
msg += _("Send message to users on kick/ban: {yes_or_no}\n").format(
yes_or_no=_("Yes") if dm_on_kickban else _("No")
)
if default_days:
msg += _("Default message history delete on ban: Previous {num_days} days\n").format(
num_days=default_days
) )
msg += _("Ban mention spam: {num_mentions}\n").format( else:
num_mentions=_("{num} mentions").format(num=ban_mention_spam) msg += _("Default message history delete on ban: Don't delete any\n")
if ban_mention_spam await ctx.send(box(msg))
else _("No")
)
msg += _("Respects hierarchy: {yes_or_no}\n").format(
yes_or_no=_("Yes") if respect_hierarchy else _("No")
)
msg += _("Delete delay: {num_seconds}\n").format(
num_seconds=_("{num} seconds").format(num=delete_delay)
if delete_delay != -1
else _("None")
)
msg += _("Reinvite on unban: {yes_or_no}\n").format(
yes_or_no=_("Yes") if reinvite_on_unban else _("No")
)
msg += _("Send message to users on kick/ban: {yes_or_no}\n").format(
yes_or_no=_("Yes") if dm_on_kickban else _("No")
)
if default_days:
msg += _(
"Default message history delete on ban: Previous {num_days} days\n"
).format(num_days=default_days)
else:
msg += _("Default message history delete on ban: Don't delete any\n")
await ctx.send(box(msg))
@modset.command() @modset.command()
@commands.guild_only() @commands.guild_only()

View File

@ -224,13 +224,15 @@ 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")
await ctx.send( async def permissions_acl_yaml_example(self, ctx: commands.Context):
_("Example YAML for setting rules:\n") """Sends an example of the yaml layout for permissions"""
+ box( await ctx.send(
textwrap.dedent( _("Example YAML for setting rules:\n")
"""\ + box(
textwrap.dedent(
"""\
COMMAND: COMMAND:
ping: ping:
12345678901234567: true 12345678901234567: true
@ -241,10 +243,10 @@ class Permissions(commands.Cog):
12345678901234567: false 12345678901234567: false
default: false default: false
""" """
), ),
lang="yaml", lang="yaml",
)
) )
)
@checks.is_owner() @checks.is_owner()
@permissions_acl.command(name="setglobal") @permissions_acl.command(name="setglobal")

View File

@ -61,23 +61,26 @@ 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:
settings = self.config.guild(ctx.guild) @triviaset.command(name="showsettings")
settings_dict = await settings.all() async def triviaset_showsettings(self, ctx: commands.Context):
msg = box( """Show the current trivia settings."""
_( settings = self.config.guild(ctx.guild)
"Current settings\n" settings_dict = await settings.all()
"Bot gains points: {bot_plays}\n" msg = box(
"Answer time limit: {delay} seconds\n" _(
"Lack of response timeout: {timeout} seconds\n" "Current settings\n"
"Points to win: {max_score}\n" "Bot gains points: {bot_plays}\n"
"Reveal answer on timeout: {reveal_answer}\n" "Answer time limit: {delay} seconds\n"
"Payout multiplier: {payout_multiplier}\n" "Lack of response timeout: {timeout} seconds\n"
"Allow lists to override settings: {allow_override}" "Points to win: {max_score}\n"
).format(**settings_dict), "Reveal answer on timeout: {reveal_answer}\n"
lang="py", "Payout multiplier: {payout_multiplier}\n"
) "Allow lists to override settings: {allow_override}"
await ctx.send(msg) ).format(**settings_dict),
lang="py",
)
await ctx.send(msg)
@triviaset.command(name="maxscore") @triviaset.command(name="maxscore")
async def triviaset_max_score(self, ctx: commands.Context, score: int): async def triviaset_max_score(self, ctx: commands.Context, score: int):

View File

@ -453,19 +453,22 @@ 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:
text = _("Embed settings:\n\n") @embedset.command(name="showsettings")
global_default = await self.bot._config.embeds() async def embedset_showsettings(self, ctx: commands.Context):
text += _("Global default: {}\n").format(global_default) """Show the current embed settings."""
if ctx.guild: text = _("Embed settings:\n\n")
guild_setting = await self.bot._config.guild(ctx.guild).embeds() global_default = await self.bot._config.embeds()
text += _("Guild setting: {}\n").format(guild_setting) text += _("Global default: {}\n").format(global_default)
if ctx.channel: if ctx.guild:
channel_setting = await self.bot._config.channel(ctx.channel).embeds() guild_setting = await self.bot._config.guild(ctx.guild).embeds()
text += _("Channel setting: {}\n").format(channel_setting) text += _("Guild setting: {}\n").format(guild_setting)
user_setting = await self.bot._config.user(ctx.author).embeds() if ctx.channel:
text += _("User setting: {}").format(user_setting) channel_setting = await self.bot._config.channel(ctx.channel).embeds()
await ctx.send(box(text)) text += _("Channel setting: {}\n").format(channel_setting)
user_setting = await self.bot._config.user(ctx.author).embeds()
text += _("User setting: {}").format(user_setting)
await ctx.send(box(text))
@embedset.command(name="global") @embedset.command(name="global")
@checks.is_owner() @checks.is_owner()
@ -939,45 +942,48 @@ 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:
if ctx.guild:
guild_data = await ctx.bot._config.guild(ctx.guild).all()
guild = ctx.guild
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_roles_str = (
humanize_list(admin_role_names) if admin_role_names else "Not Set."
)
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_roles_str = humanize_list(mod_role_names) if mod_role_names else "Not Set."
guild_settings = _("Admin roles: {admin}\nMod roles: {mod}\n").format(
admin=admin_roles_str, mod=mod_roles_str
)
else:
guild_settings = ""
prefixes = await ctx.bot._prefix_cache.get_prefixes(ctx.guild) @_set.command("showsettings")
global_data = await ctx.bot._config.all() async def set_showsettings(self, ctx: commands.Context):
locale = global_data["locale"] """
regional_format = global_data["regional_format"] or _("Same as bot's locale") Show the current settings for [botname].
"""
prefix_string = " ".join(prefixes) if ctx.guild:
settings = _( guild_data = await ctx.bot._config.guild(ctx.guild).all()
"{bot_name} Settings:\n\n" guild = ctx.guild
"Prefixes: {prefixes}\n" admin_role_ids = guild_data["admin_role"]
"{guild_settings}" admin_role_names = [r.name for r in guild.roles if r.id in admin_role_ids]
"Locale: {locale}\n" admin_roles_str = humanize_list(admin_role_names) if admin_role_names else "Not Set."
"Regional format: {regional_format}" mod_role_ids = guild_data["mod_role"]
).format( mod_role_names = [r.name for r in guild.roles if r.id in mod_role_ids]
bot_name=ctx.bot.user.name, mod_roles_str = humanize_list(mod_role_names) if mod_role_names else "Not Set."
prefixes=prefix_string, guild_settings = _("Admin roles: {admin}\nMod roles: {mod}\n").format(
guild_settings=guild_settings, admin=admin_roles_str, mod=mod_roles_str
locale=locale,
regional_format=regional_format,
) )
for page in pagify(settings): else:
await ctx.send(box(page)) guild_settings = ""
prefixes = await ctx.bot._prefix_cache.get_prefixes(ctx.guild)
global_data = await ctx.bot._config.all()
locale = global_data["locale"]
regional_format = global_data["regional_format"] or _("Same as bot's locale")
prefix_string = " ".join(prefixes)
settings = _(
"{bot_name} Settings:\n\n"
"Prefixes: {prefixes}\n"
"{guild_settings}"
"Locale: {locale}\n"
"Regional format: {regional_format}"
).format(
bot_name=ctx.bot.user.name,
prefixes=prefix_string,
guild_settings=guild_settings,
locale=locale,
regional_format=regional_format,
)
for page in pagify(settings):
await ctx.send(box(page))
@checks.guildowner_or_permissions(administrator=True) @checks.guildowner_or_permissions(administrator=True)
@_set.command(name="deletedelay") @_set.command(name="deletedelay")
@ -2550,9 +2556,14 @@ 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:
for page in pagify(await self.count_ignored(ctx)): @ignore.command(name="list")
await ctx.maybe_send_embed(page) async def ignore_list(self, ctx: commands.Context):
"""
List the currently ignored servers and channels
"""
for page in pagify(await self.count_ignored(ctx)):
await ctx.maybe_send_embed(page)
@ignore.command(name="channel") @ignore.command(name="channel")
async def ignore_channel( async def ignore_channel(
@ -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(