Add a command to set the bot description (#3340)

* description-command

* Cap the description length

* mmk
This commit is contained in:
Michael H 2020-01-13 10:12:31 -05:00 committed by GitHub
parent ab2e87a8fb
commit ef8b57a1d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 3 deletions

View File

@ -76,6 +76,7 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
help__verify_checks=True, help__verify_checks=True,
help__verify_exists=False, help__verify_exists=False,
help__tagline="", help__tagline="",
description="Red V3",
invite_public=False, invite_public=False,
invite_perm=0, invite_perm=0,
disabled_commands=[], disabled_commands=[],
@ -400,6 +401,7 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
This should only be run once, prior to connecting to discord. This should only be run once, prior to connecting to discord.
""" """
await self._maybe_update_config() await self._maybe_update_config()
self.description = await self._config.description()
init_global_checks(self) init_global_checks(self)
init_events(self, cli_flags) init_events(self, cli_flags)

View File

@ -198,7 +198,7 @@ class RedHelpFormatter:
emb = {"embed": {"title": "", "description": ""}, "footer": {"text": ""}, "fields": []} emb = {"embed": {"title": "", "description": ""}, "footer": {"text": ""}, "fields": []}
if description: if description:
emb["embed"]["title"] = f"*{description[:2044]}*" emb["embed"]["title"] = f"*{description[:250]}*"
emb["footer"]["text"] = tagline emb["footer"]["text"] = tagline
emb["embed"]["description"] = signature emb["embed"]["description"] = signature
@ -209,7 +209,7 @@ class RedHelpFormatter:
value = "\n\n".join(splitted[1:]).replace("[p]", ctx.clean_prefix) value = "\n\n".join(splitted[1:]).replace("[p]", ctx.clean_prefix)
if not value: if not value:
value = EMPTY_STRING value = EMPTY_STRING
field = EmbedField(name[:252], value[:1024], False) field = EmbedField(name[:250], value[:1024], False)
emb["fields"].append(field) emb["fields"].append(field)
if subcommands: if subcommands:
@ -442,7 +442,7 @@ class RedHelpFormatter:
emb["footer"]["text"] = tagline emb["footer"]["text"] = tagline
if description: if description:
emb["embed"]["title"] = f"*{description[:2044]}*" emb["embed"]["title"] = f"*{description[:250]}*"
for cog_name, data in coms: for cog_name, data in coms:

View File

@ -873,6 +873,32 @@ class Core(commands.Cog, CoreLogic):
for page in pagify(settings): for page in pagify(settings):
await ctx.send(box(page)) await ctx.send(box(page))
@checks.is_owner()
@_set.command(name="description")
async def setdescription(self, ctx: commands.Context, *, description: str = ""):
"""
Sets the bot's description.
Use without a description to reset.
This is shown in a few locations, including the help menu.
The default is "Red V3"
"""
if not description:
await ctx.bot._config.description.clear()
ctx.bot.description = "Red V3"
await ctx.send(_("Description reset."))
elif len(description) > 250: # While the limit is 256, we bold it adding characters.
await ctx.send(
_(
"This description is too long to properly display. "
"Please try again with below 250 characters"
)
)
else:
await ctx.bot._config.description.set(description)
ctx.bot.description = description
await ctx.tick()
@_set.command() @_set.command()
@checks.guildowner() @checks.guildowner()
@commands.guild_only() @commands.guild_only()