Add commands for editing aliases (#5108)

* [Alias] Added alias edit and alias global edit

* Comment and whitespace only changes

* Docstring fix

* Remove more whitespace

* Add `the` before some English purists make a PR for this...

Co-authored-by: npc203 <npc203@users.noreply.github.com>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Samuel
2021-09-03 07:20:08 +05:30
committed by GitHub
parent 6d40de8da3
commit cad7f400f9
2 changed files with 105 additions and 3 deletions

View File

@@ -338,6 +338,75 @@ class Alias(commands.Cog):
)
)
@checks.mod_or_permissions(manage_guild=True)
@alias.command(name="edit")
@commands.guild_only()
async def _edit_alias(self, ctx: commands.Context, alias_name: str, *, command):
"""Edit an existing alias in this server."""
# region Alias Add Validity Checking
alias = await self._aliases.get_alias(ctx.guild, alias_name)
if not alias:
await ctx.send(
_("The alias with the name {name} does not exist.").format(name=alias_name)
)
return
given_command_exists = self.bot.get_command(command.split(maxsplit=1)[0]) is not None
if not given_command_exists:
await ctx.send(_("You attempted to edit an alias to a command that doesn't exist."))
return
# endregion
# So we figured it is a valid alias and the command exists
# we can go ahead editing the command
try:
if await self._aliases.edit_alias(ctx, alias_name, command):
await ctx.send(
_("The alias with the trigger `{name}` has been edited sucessfully.").format(
name=alias_name
)
)
else:
# This part should technically never be reached...
await ctx.send(
_("Alias with the name `{name}` was not found.").format(name=alias_name)
)
except ArgParseError as e:
return await ctx.send(" ".join(e.args))
@checks.is_owner()
@global_.command(name="edit")
async def _edit_global_alias(self, ctx: commands.Context, alias_name: str, *, command):
"""Edit an existing global alias."""
# region Alias Add Validity Checking
alias = await self._aliases.get_alias(None, alias_name)
if not alias:
await ctx.send(
_("The alias with the name {name} does not exist.").format(name=alias_name)
)
return
given_command_exists = self.bot.get_command(command.split(maxsplit=1)[0]) is not None
if not given_command_exists:
await ctx.send(_("You attempted to edit an alias to a command that doesn't exist."))
return
# endregion
try:
if await self._aliases.edit_alias(ctx, alias_name, command, global_=True):
await ctx.send(
_("The alias with the trigger `{name}` has been edited sucessfully.").format(
name=alias_name
)
)
else:
# This part should technically never be reached...
await ctx.send(
_("Alias with the name `{name}` was not found.").format(name=alias_name)
)
except ArgParseError as e:
return await ctx.send(" ".join(e.args))
@alias.command(name="help")
async def _help_alias(self, ctx: commands.Context, alias_name: str):
"""Try to execute help for the base command of the alias."""