diff options
author | 2019-10-01 11:34:24 +0200 | |
---|---|---|
committer | 2019-10-01 11:34:24 +0200 | |
commit | 4c3714bf406ff750ddc306457f41b4871160338f (patch) | |
tree | db64bba793dfd5e6efb774e24f3f7fe7b8638e1a | |
parent | Adjust development workflow inline with new `site` changes. (#464) (diff) |
Make `!tags edit` use PATCH to update tags
https://github.com/python-discord/bot/issues/474
This commit makes sure we're using the PATCH method to update tags,
instead of the POST method. The problem was that the `!tags edit`
command was an alias of `!tags set`, which uses the POST method to
post new tags to the API.
However, when a tag with a given name already exists, the API will
refuse a POST request in an attempt to update it; we need to use the
PATCH method to the `bot/tags/{tag_name}` endpoint instead.
I fixed this by creating a separate subcommand, `!tags edit`, that
uses the correct PATCH method to update an existing tag.
This commit closes #474
-rw-r--r-- | bot/cogs/tags.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py index b9dd3595e..cd70e783a 100644 --- a/bot/cogs/tags.py +++ b/bot/cogs/tags.py @@ -86,7 +86,7 @@ class Tags(Cog): max_lines=15 ) - @tags_group.command(name='set', aliases=('add', 'edit', 's')) + @tags_group.command(name='set', aliases=('add', 's')) @with_role(*MODERATION_ROLES) async def set_command( self, @@ -95,7 +95,7 @@ class Tags(Cog): *, tag_content: TagContentConverter, ) -> None: - """Create a new tag or update an existing one.""" + """Create a new tag.""" body = { 'title': tag_name.lower().strip(), 'embed': { @@ -116,6 +116,35 @@ class Tags(Cog): colour=Colour.blurple() )) + @tags_group.command(name='edit', aliases=('e', )) + @with_role(*MODERATION_ROLES) + async def edit_command( + self, + ctx: Context, + tag_name: TagNameConverter, + *, + tag_content: TagContentConverter, + ) -> None: + """Edit an existing tag.""" + body = { + 'embed': { + 'title': tag_name, + 'description': tag_content + } + } + + await self.bot.api_client.patch(f'bot/tags/{tag_name}', json=body) + + log.debug(f"{ctx.author} successfully edited the following tag in our database: \n" + f"tag_name: {tag_name}\n" + f"tag_content: '{tag_content}'\n") + + await ctx.send(embed=Embed( + title="Tag successfully edited", + description=f"**{tag_name}** edited in the database.", + colour=Colour.blurple() + )) + @tags_group.command(name='delete', aliases=('remove', 'rm', 'd')) @with_role(Roles.admin, Roles.owner) async def delete_command(self, ctx: Context, *, tag_name: TagNameConverter) -> None: |