From d2e841f681b017c5d7a50a20c2c7eeb917a96f6a Mon Sep 17 00:00:00 2001 From: Bakersbakebread <29239704+Bakersbakebread@users.noreply.github.com> Date: Mon, 19 Feb 2018 02:44:45 +0000 Subject: [PATCH] [V3] Add prompt if message deletion > 100 (#1304) * Add prompt if message deletion > 100 As per issue #1295. Add's the prompt "Are you sure you want to delete {number} messages? (y/n)" * added checks and deletes "Continuing" message phew * removed unneeded delete() Removed the unneeded code --- redbot/cogs/cleanup/cleanup.py | 66 +++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py index 04ff18bcf..63bd76e31 100644 --- a/redbot/cogs/cleanup/cleanup.py +++ b/redbot/cogs/cleanup/cleanup.py @@ -41,7 +41,20 @@ class Cleanup: channel = ctx.channel author = ctx.author is_bot = self.bot.user.bot + + def author_check(message): + return message.author == author + if number > 100: + await ctx.send('Are you sure you want to delete {} messages? (y/n)'.format(number)) + response = await self.bot.wait_for('message', check=author_check) + + if response.content.startswith('y'): + tmp = await ctx.send('Continuing..') + await tmp.delete() + else: + return await ctx.send('Cancelled.') + def check(m): if text in m.content: return True @@ -90,6 +103,19 @@ class Cleanup: channel = ctx.channel author = ctx.author is_bot = self.bot.user.bot + + def author_check(message): + return message.author == author + + if number > 100: + await ctx.send('Are you sure you want to delete {} messages? (y/n)'.format(number)) + response = await self.bot.wait_for('message', check=author_check) + + if response.content.startswith('y'): + tmp = await ctx.send('Continuing..') + await tmp.delete() + else: + return await ctx.send('Cancelled.') def check(m): if isinstance(user, discord.Member) and m.author == user: @@ -185,9 +211,21 @@ class Cleanup: author = ctx.author is_bot = self.bot.user.bot + + def author_check(message): + return message.author == author + + if number > 100: + await ctx.send('Are you sure you want to delete {} messages? (y/n)'.format(number)) + response = await self.bot.wait_for('message', check=author_check) + + if response.content.startswith('y'): + tmp = await ctx.send('Continuing..') + await tmp.delete() + else: + return await ctx.send('Cancelled.') to_delete = [] - tmp = ctx.message done = False @@ -221,6 +259,19 @@ class Cleanup: author = ctx.message.author is_bot = self.bot.user.bot + def author_check(message): + return message.author == author + + if number > 100: + await ctx.send('Are you sure you want to delete {} messages? (y/n)'.format(number)) + response = await self.bot.wait_for('message', check=author_check) + + if response.content.startswith('y'): + tmp = await ctx.send('Continuing..') + await tmp.delete() + else: + return await ctx.send('Cancelled.') + prefixes = await self.bot.get_prefix(ctx.message) # This returns all server prefixes if isinstance(prefixes, str): prefixes = [prefixes] @@ -283,6 +334,19 @@ class Cleanup: author = ctx.message.author is_bot = self.bot.user.bot + def author_check(message): + return message.author == author + + if number > 100: + await ctx.send('Are you sure you want to delete {} messages? (y/n)'.format(number)) + response = await self.bot.wait_for('message', check=author_check) + + if response.content.startswith('y'): + tmp = await ctx.send('Continuing..') + await tmp.delete() + else: + return await ctx.send('Cancelled.') + # You can always delete your own messages, this is needed to purge can_mass_purge = False if type(author) is discord.Member: