async def set_command( self, ctx: Context, tag_name: TagNameConverter, *, tag_content: TagContentConverter, ) -> None: """Create a new tag.""" body = { 'title': tag_name.lower().strip(), 'embed': { 'title': tag_name, 'description': tag_content } } await self.bot.api_client.post('bot/tags', json=body) self._cache[tag_name.lower()] = await self.bot.api_client.get(f'bot/tags/{tag_name}') log.debug(f"{ctx.author} successfully added the following tag to our database: \n" f"tag_name: {tag_name}\n" f"tag_content: '{tag_content}'\n") await ctx.send(embed=Embed( title="Tag successfully added", description=f"**{tag_name}** added to tag database.", colour=Colour.blurple() ))
async def set_command( self, ctx: Context, tag_name: TagNameConverter, *, tag_content: TagContentConverter, ): """ Create a new tag or update an existing one. :param ctx: discord message context :param tag_name: The name of the tag to create or edit. :param tag_content: The content of the tag. """ body = { 'title': tag_name.lower().strip(), 'embed': { 'title': tag_name, 'description': tag_content } } await self.bot.api_client.post('bot/tags', json=body) log.debug(f"{ctx.author} successfully added the following tag to our database: \n" f"tag_name: {tag_name}\n" f"tag_content: '{tag_content}'\n") await ctx.send(embed=Embed( title="Tag successfully added", description=f"**{tag_name}** added to tag database.", colour=Colour.blurple() ))
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) self._cache[tag_name.lower()] = await self.bot.api_client.get(f'bot/tags/{tag_name}') 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() ))
async def delete_command(self, ctx: Context, *, tag_name: TagNameConverter): """ Remove a tag from the database. :param ctx: discord message context :param tag_name: The name of the tag to delete. """ tag_name = tag_name.lower().strip() embed = Embed() embed.colour = Colour.red() tag_data = await self.delete_tag_data(tag_name) if tag_data.get("success") is True: log.debug(f"{ctx.author} successfully deleted the tag called '{tag_name}'") embed.colour = Colour.blurple() embed.title = tag_name embed.description = f"Tag successfully removed: {tag_name}." elif tag_data.get("success") is False: log.debug(f"{ctx.author} tried to delete a tag called '{tag_name}', but the tag does not exist.") embed.colour = Colour.red() embed.title = tag_name embed.description = "Tag doesn't appear to exist." else: log.error("There was an unexpected database error when trying to delete the following tag: \n" f"tag_name: {tag_name}\n" f"response: {tag_data}") embed.title = "Database error" embed.description = ("There was an unexpected error with deleting the data from the tags database. " "Please try again. If the problem persists, see the error logs.") return await ctx.send(embed=embed)
async def delete_command(self, ctx: Context, *, tag_name: TagNameConverter) -> None: """Remove a tag from the database.""" await self.bot.api_client.delete(f'bot/tags/{tag_name}') self._cache.pop(tag_name.lower(), None) log.debug(f"{ctx.author} successfully deleted the tag called '{tag_name}'") await ctx.send(embed=Embed( title=tag_name, description=f"Tag successfully removed: {tag_name}.", colour=Colour.blurple() ))
async def set_command(self, ctx: Context, tag_name: TagNameConverter, tag_content: TagContentConverter, image_url: ValidURL = None): """ Create a new tag or edit an existing one. :param ctx: discord message context :param tag_name: The name of the tag to create or edit. :param tag_content: The content of the tag. :param image_url: An optional image for the tag. """ tag_name = tag_name.lower().strip() tag_content = tag_content.strip() embed = Embed() embed.colour = Colour.red() tag_data = await self.post_tag_data(tag_name, tag_content, image_url) if tag_data.get("success"): log.debug( f"{ctx.author} successfully added the following tag to our database: \n" f"tag_name: {tag_name}\n" f"tag_content: '{tag_content}'\n" f"image_url: '{image_url}'") embed.colour = Colour.blurple() embed.title = "Tag successfully added" embed.description = f"**{tag_name}** added to tag database." else: log.error( "There was an unexpected database error when trying to add the following tag: \n" f"tag_name: {tag_name}\n" f"tag_content: '{tag_content}'\n" f"image_url: '{image_url}'\n" f"response: {tag_data}") embed.title = "Database error" embed.description = ( "There was a problem adding the data to the tags database. " "Please try again. If the problem persists, see the error logs." ) return await ctx.send(embed=embed)