async def quote_delete(self, ctx: commands.Context, user: str, number): """!kazhelp description: Delete one or all quotes attributed to a user. This is a moderative command; regular users should use {{!quote undo}} or {{!quote rem}}. parameters: - name: user type: "@user" description: The user whose quote to delete. Can be an @mention or discord ID. - name: number type: number or "all" description: The ID number of the quote to delete (starting from 1), or "all". examples: - command: .quote rem @JaneDoe#0921 4 description: Delete the 4th quote by JaneDoe. - command: .quote rem @JaneDoe#0921 all description: Remove all quotes by JaneDoe. """ db_user = c.query_user(self.server, user) len_recs = len(db_user.quotes) if number == 'all': logger.info("Removing all {} quotes for {!r}...".format( len_recs, db_user)) c.remove_quotes(db_user.quotes) await self.bot.say("Removed all {} quotes for {}.".format( len_recs, db_user.mention)) await self.send_output("Removed all {} quotes for {}.".format( len_recs, db_user.mention)) else: try: number = int(number) except ValueError: raise commands.BadArgument( "The number of the quote to delete is required.") if number < 1 or number > len_recs: logger.warning("Invalid index {:d}".format(number)) await self.bot.say( "Oops, I can't get quote {:d} for {}! Valid quotes are 1 to {:d}" .format(number, db_user.name, len_recs)) return quote = db_user.quotes[number - 1] message_text = "Removed quote (mod): {}".format( self.format_quote(quote)) em = self.make_single_embed(quote, number, len_recs, title="Quote deleted.") c.remove_quotes([quote]) await self.bot.say(embed=em) await self.send_output(message_text)
async def quote_delete(self, ctx: commands.Context, user: str, number): """ [MOD ONLY] Delete one or all quotes attributed to a user. Arguments: * user: Required. The user to find a quote for. See `.help quote` for valid formats. * number: Required. The ID number of the quote to delete (starting from 1), or "all". Examples: .quote rem @JaneDoe 4 - Delete the 4th quote by JaneDoe. .quote rem @JaneDoe all - Remove all quotes by JaneDoe. """ logger.info("quote del: {}".format(message_log_str(ctx.message))) db_user = c.query_user(self.server, user) db_records = c.query_author_quotes(db_user) len_recs = len(db_records) if number == 'all': logger.info("Removing all {} quotes for {!r}...".format( len_recs, db_user)) c.remove_quotes(db_records) await self.bot.say("Removed all {} quotes for {}.".format( len_recs, db_user.mention)) await self.send_output("Removed all {} quotes for {}.".format( len_recs, db_user.mention)) else: try: number = int(number) except ValueError: raise commands.BadArgument("Cannot convert number to int") if number < 1 or number > len_recs: logger.warning("Invalid index {:d}".format(number)) await self.bot.say( "Oops, I can't get quote {:d} for {}! Valid quotes are 1 to {:d}" .format(number, db_user.name, len_recs)) return quote = db_records[number - 1] message_text = "Removed quote (mod): {}".format( self.format_quote(quote)) em = self.make_single_embed(quote, number, len_recs, title="Quote deleted.") c.remove_quotes([quote]) await self.bot.say(embed=em) await self.send_output(message_text)
async def quote_remove(self, ctx: commands.Context, number: int): """!kazhelp description: | Remove one of your own quotes. WARNING: This command cannot be undone! IMPORTANT: If you are being harassed via quotes, or quote are otherwise being abused, please report this to the mods. TIP: To delete a quote you quoted (instead of a quote attributed to you), use {{!quote undo}} to remove the most recent one. For any other situation, contact the mods. parameters: - name: number type: number description: The ID number of the quote to delete (starting from 1), as shown by the {{!quote}}, {{!quote get}} and {{!quote list}} commands. examples: - command: .quote del 4 description: Delete the 4th quote attributed to you. """ db_user = c.query_user(self.server, ctx.message.author.id) len_recs = len(db_user.quotes) if number < 1 or number > len_recs: logger.warning("Invalid index {:d}".format(number)) await self.bot.say( "Oops, I can't get quote {:d} for {}! Valid quotes are 1 to {:d}" .format(number, db_user.name, len_recs)) return quote = db_user.quotes[number - 1] message_text = "Removed quote (remove): {}".format( self.format_quote(quote)) em = self.make_single_embed(quote, number, len_recs, title="Quote deleted.") c.remove_quotes([quote]) await self.bot.say(embed=em) await self.send_output(message_text)
async def quote_undo(self, ctx: commands.Context): """!kazhelp description: | Remove the last quote you added. WARNING: This command cannot be undone! TIP: This command only undoes your own calls to {{!quote add}} or {{!quote grab}}. It does **not** undo {{!quote rem}}, and does not undo quote commands by other users. TIP: To delete quotes attributed to you, use {{!quote rem}}. """ db_user = c.query_user(self.server, ctx.message.author.id) quote = db_user.saved_quotes[-1] message_text = "Removed quote (undo): {}".format( self.format_quote(quote)) em = self.make_single_embed(quote, title="Quote deleted.") c.remove_quotes([quote]) await self.bot.say(embed=em) await self.send_output(message_text)
async def quote_undo(self, ctx: commands.Context): """ Remove the last quote you added. THIS COMMAND CANNOT BE UNDONE. This command only undoes `.quote add` or `.quote grab` actions. It does NOT undo `.quote rem` actions. """ logger.info("quote undo: {}".format(message_log_str(ctx.message))) db_user = c.query_user(self.server, ctx.message.author.id) db_records = c.query_saved_quotes(db_user) quote = db_records[-1] message_text = "Removed quote (undo): {}".format( self.format_quote(quote)) em = self.make_single_embed(quote, title="Quote deleted.") c.remove_quotes([quote]) await self.bot.say(embed=em) await self.send_output(message_text)
async def quote_remove(self, ctx: commands.Context, number: int): """ Remove one of your own quotes. THIS COMMAND CANNOT BE UNDONE. This command is limited to quotes attributed to you. For any other situations, please contact the moderators to delete quotes. Arguments: * number: Optional. The ID number of the quote to delete (starting from 1), as shown by the `.quote` or `.quote list` commands. Examples: .quote del 4 - Delete the 4th quote attributed to you. """ logger.info("quote rem: {}".format(message_log_str(ctx.message))) db_user = c.query_user(self.server, ctx.message.author.id) db_records = c.query_author_quotes(db_user) len_recs = len(db_records) if number < 1 or number > len_recs: logger.warning("Invalid index {:d}".format(number)) await self.bot.say( "Oops, I can't get quote {:d} for {}! Valid quotes are 1 to {:d}" .format(number, db_user.name, len_recs)) return quote = db_records[number - 1] message_text = "Removed quote (remove): {}".format( self.format_quote(quote)) em = self.make_single_embed(quote, number, len_recs, title="Quote deleted.") c.remove_quotes([quote]) await self.bot.say(embed=em) await self.send_output(message_text)