From 5312e7a18b4bc72fb3fdde32643d60846b4cee06 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 17 Oct 2017 18:02:00 -0400 Subject: [PATCH] Converted history flattening and check to async iteration --- src/main/cogs/management.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/cogs/management.py b/src/main/cogs/management.py index 10a41b8..67c669b 100644 --- a/src/main/cogs/management.py +++ b/src/main/cogs/management.py @@ -58,26 +58,30 @@ class Administration: async for message in channel.history(limit=None): if message.author.id == int(user): history.append(message) - # history.extend(await channel.history(limit=None).flatten()) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) elif when == 'before': for channel in channels: - history.extend(await channel.history(limit=None, before=ref.created_at).flatten()) + async for message in channel.history(limit=None, before=ref.created_at): + if message.author.id == int(user): + history.append(message) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) elif when == 'after': for channel in channels: - history.extend(await channel.history(limit=None, after=ref.created_at).flatten()) + async for message in channel.history(limit=None, after=ref.created_at): + if message.author.id == int(user): + history.append(message) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) elif when == 'about': for channel in channels: - history.extend(await channel.history(limit=101, about=ref.created_at).flatten()) + async for message in channel.history(limit=None, about=ref.created_at): + if message.author.id == int(user): + history.append(message) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) - # history = [message for message in history if message.author.id == user] est_sent = await ctx.send('⏱ **Estimated time to delete history:** `{}m {}s`'.format(int(self.RATE_LIMIT * len(history) / 60), int(self.RATE_LIMIT * len(history) % 60))) cont_sent = await ctx.send('{} **Continue?** `Y` or `N`'.format(ctx.author.mention)) await self.bot.wait_for('message', check=yes, timeout=10 * 60)