From 6ee7a251d4c4edc52665645f67aa200cc63668f4 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:39:04 -0400 Subject: [PATCH 01/13] Removed redundant global definition --- src/main/utils/utils.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/utils/utils.py b/src/main/utils/utils.py index 6ace555..71e5eb1 100644 --- a/src/main/utils/utils.py +++ b/src/main/utils/utils.py @@ -87,8 +87,6 @@ session = aiohttp.ClientSession() def close(loop): - global session - if session: session.close() @@ -104,8 +102,6 @@ def close(loop): async def fetch(url, *, params={}, json=False): - global session - async with session.get(url, params=params, headers={'User-Agent': 'Myned/Modumind/dev'}) as r: if json: return await r.json() From e74a3b0bc3dc840800f032c31ce5a3e9e6add6a0 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:40:14 -0400 Subject: [PATCH 02/13] Optimized arg cleaning --- src/main/utils/utils.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/utils/utils.py b/src/main/utils/utils.py index 71e5eb1..cf323c8 100644 --- a/src/main/utils/utils.py +++ b/src/main/utils/utils.py @@ -117,19 +117,17 @@ def get_kwargs(ctx, args, *, limit=False): rm = False lim = 1 - if '-d' in remaining or '-dm' in remaining: - destination = ctx.author + for flag in ('-d', '-dm'): + if flag in remaining: + destination = ctx.author - for flag in ('-d', '-dm'): - with suppress(ValueError): - remaining.remove(flag) + remaining.remove(flag) - if ('-r' in remaining or '-rm' in remaining or '-remove' in remaining) and ctx.author.permissions_in(ctx.channel).manage_messages: - rm = True + for flag in ('-r', '-rm', '-remove', '-re', '-repl', '-replace'): + if flag in remaining and ctx.author.permissions_in(ctx.channel).manage_messages: + rm = True - for flag in ('-r', '-rm', '-remove'): - with suppress(ValueError): - remaining.remove(flag) + remaining.remove(flag) if limit: for arg in remaining: From 945840783b19daf11e7513677ba5b02a20ebb02a Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:41:11 -0400 Subject: [PATCH 03/13] Removed bot user check for on_message for *ifying embeds --- src/main/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/run.py b/src/main/run.py index 582fd9c..0503665 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -59,7 +59,7 @@ async def on_ready(): @bot.event async def on_message(message): - if message.author.bot or message.author is bot.user: + if message.author is bot.user: return await bot.process_commands(message) From 10b876299aa7e7b7e5f9eba46e3169bcb92a3019 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:42:02 -0400 Subject: [PATCH 04/13] =?UTF-8?q?Changed=20=E2=9D=8C=20to=20=E2=9D=93=20fo?= =?UTF-8?q?r=20missing=20commands=20for=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/run.py b/src/main/run.py index 0503665..44804c3 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -88,7 +88,7 @@ async def on_command_error(ctx, error): await ctx.message.add_reaction('\N{NO ENTRY}') elif isinstance(error, errext.CommandNotFound): print('INVALID COMMAND : {}'.format(error), file=sys.stderr) - await ctx.message.add_reaction('\N{CROSS MARK}') + await ctx.message.add_reaction('\N{BLACK QUESTION MARK ORNAMENT}') else: print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format( error), file=sys.stderr) From 7652f276cc912aa2a9ac164dca6767cff8c875fe Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:43:29 -0400 Subject: [PATCH 05/13] Increased *ify limit to 30 --- src/main/cogs/booru.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 0ba02d8..98554cd 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -23,7 +23,7 @@ class MsG: self.bot = bot self.color = d.Color(0x1A1A1A) self.LIMIT = 100 - self.HISTORY_LIMIT = 100 + self.HISTORY_LIMIT = 150 self.RATE_LIMIT = u.RATE_LIMIT self.qualiqueue = asyncio.Queue() self.qualitifying = False @@ -326,17 +326,17 @@ class MsG: with suppress(err.NotFound): await message.delete() - except exc.MatchError as e: - await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) - await message.add_reaction('\N{CROSS MARK}') + except exc.MatchError as e: + await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) + await message.add_reaction('\N{CROSS MARK}') - await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.NotFound: await ctx.send('**No matches found.**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.BoundsError as e: - await ctx.send('`{}` **invalid limit.** Images limited to 20'.format(e), delete_after=10) + await ctx.send('`{}` **invalid limit.** Query limited to 30'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @commands.command(name='qualitify', aliases=['qualify', 'qrevify', 'qrisify', 'qify']) @@ -400,17 +400,17 @@ class MsG: with suppress(err.NotFound): await message.delete() - except exc.MatchError as e: - await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) - await message.add_reaction('\N{CROSS MARK}') + except exc.MatchError as e: + await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) + await message.add_reaction('\N{CROSS MARK}') - await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.NotFound: await ctx.send('**No matches found.**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.BoundsError as e: - await ctx.send('`{}` **invalid limit.** Images limited to 20'.format(e), delete_after=10) + await ctx.send('`{}` **invalid limit.** Query limited to 30'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') async def _qualitify(self): From 844afd86007be80a99eec5be9767f12f95a10e6d Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:43:51 -0400 Subject: [PATCH 06/13] Commented out WIP autopost command --- src/main/cogs/booru.py | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 98554cd..72a718c 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -41,29 +41,29 @@ class MsG: self.bot.loop.create_task(self._qualitify()) self.qualitifying = True - async def get_post(self, channel): - post_request = await u.fetch('https://e621.net/post/index.json', json=True) - - @commands.command() - async def auto_post(self, ctx): - try: - if ctx.channel.id not in u.tasks['auto_post']: - u.tasks['auto_post'].append(ctx.channel.id) - u.dump(u.tasks, 'cogs/tasks.pkl') - self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel)) - if not self.qualitifying: - self.bot.loop.create_task(self._qualitify()) - self.qualitifying = True - - print('AUTO-POSTING : #{}'.format(ctx.channel.name)) - await ctx.send('**Auto-posting all images in {}.**'.format(ctx.channel.mention), delete_after=5) - await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - else: - raise exc.Exists - - except exc.Exists: - await ctx.send('**Already auto-posting in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=10) - await ctx.message.add_reaction('\N{CROSS MARK}') + # async def get_post(self, channel): + # post_request = await u.fetch('https://e621.net/post/index.json', json=True) + # + # @commands.command() + # async def auto_post(self, ctx): + # try: + # if ctx.channel.id not in u.tasks['auto_post']: + # u.tasks['auto_post'].append(ctx.channel.id) + # u.dump(u.tasks, 'cogs/tasks.pkl') + # self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel)) + # if not self.qualitifying: + # self.bot.loop.create_task(self._qualitify()) + # self.qualitifying = True + # + # print('AUTO-POSTING : #{}'.format(ctx.channel.name)) + # await ctx.send('**Auto-posting all images in {}.**'.format(ctx.channel.mention), delete_after=5) + # await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + # else: + # raise exc.Exists + # + # except exc.Exists: + # await ctx.send('**Already auto-posting in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=10) + # await ctx.message.add_reaction('\N{CROSS MARK}') # Tag search @commands.command(aliases=['rel'], brief='e621 Search for related tags', description='e621 | NSFW\nReturn related tags for a number of given tags', usage='[related|rel]') From 985791e574ff54755d904e69cee971b174810121 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:44:37 -0400 Subject: [PATCH 07/13] Removed colon from match output --- src/main/cogs/booru.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 72a718c..0bf1f7e 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -192,7 +192,7 @@ class MsG: try: await dest.trigger_typing() - await dest.send('**Probable match:**\n{}'.format(await scraper.get_post(url))) + await dest.send('**Probable match**\n{}'.format(await scraper.get_post(url))) c += 1 await asyncio.sleep(self.RATE_LIMIT) @@ -204,7 +204,7 @@ class MsG: try: await dest.trigger_typing() - await dest.send('**Probable match:**\n{}'.format(await scraper.get_post(attachment.url))) + await dest.send('**Probable match**\n{}'.format(await scraper.get_post(attachment.url))) c += 1 await asyncio.sleep(self.RATE_LIMIT) @@ -238,7 +238,7 @@ class MsG: post = await scraper.get_post(url) - await dest.send('**Probable match:**\n{}'.format(await scraper.get_image(post))) + await dest.send('**Probable match**\n{}'.format(await scraper.get_image(post))) c += 1 await asyncio.sleep(self.RATE_LIMIT) @@ -252,7 +252,7 @@ class MsG: post = await scraper.get_post(attachment.url) - await dest.send('**Probable match:**\n{}'.format(await scraper.get_image(post))) + await dest.send('**Probable match**\n{}'.format(await scraper.get_image(post))) c += 1 await asyncio.sleep(self.RATE_LIMIT) From dcc251496bf1a36267bbe618054989e6d33a1a60 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 15:45:28 -0400 Subject: [PATCH 08/13] Added current / total *ify status --- src/main/cogs/booru.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 0bf1f7e..5a304fe 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -286,10 +286,10 @@ class MsG: break if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None: urls.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') elif message.author.id != self.bot.user.id and message.attachments: attachments.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') if not urls and not attachments: raise exc.NotFound @@ -314,13 +314,13 @@ class MsG: for message in attachments: for attachment in message.attachments: - try: - await dest.trigger_typing() + try: + await dest.trigger_typing() - await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_post(attachment.url))) - await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await dest.send('**Probable match from** {} `{} / {}`\n{}'.format(message.author.display_name, urls.index(url) + 1, len(urls), await scraper.get_post(url))) + await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - await asyncio.sleep(self.RATE_LIMIT) + await asyncio.sleep(self.RATE_LIMIT) if remove: with suppress(err.NotFound): @@ -356,10 +356,10 @@ class MsG: break if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None: urls.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') elif message.author.id != self.bot.user.id and message.attachments: attachments.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') if not urls and not attachments: raise exc.NotFound @@ -386,15 +386,15 @@ class MsG: for message in attachments: for attachment in message.attachments: - try: - await dest.trigger_typing() + try: + await dest.trigger_typing() post = await scraper.get_post(attachment.url) - await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post))) - await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await dest.send('**Probable match from** {} `{} / {}`\n{}'.format(message.author.display_name, urls.index(url) + 1, len(urls), await scraper.get_image(post))) + await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - await asyncio.sleep(self.RATE_LIMIT) + await asyncio.sleep(self.RATE_LIMIT) if remove: with suppress(err.NotFound): From ddc020e11dbcd36d0f8b6a18be6a02f8d4bef720 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 16:28:16 -0400 Subject: [PATCH 09/13] Removed periods from output for aesthetic purposes --- src/main/cogs/booru.py | 106 ++++++++++++++++++------------------ src/main/cogs/management.py | 26 ++++----- src/main/cogs/tools.py | 4 +- src/main/run.py | 2 +- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 5a304fe..39e0cbc 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -173,7 +173,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.MissingArgument: - await ctx.send('**Invalid url or file.**', delete_after=10) + await ctx.send('**Invalid url or file**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') # Reverse image searches a linked image using the public iqdb @@ -218,7 +218,7 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') except exc.MissingArgument: - await ctx.send('**Invalid url or file.**', delete_after=10) + await ctx.send('**Invalid url or file**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @commands.command(name='quality', aliases=['qual', 'qrev', 'qis']) @@ -266,7 +266,7 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') except exc.MissingArgument: - await ctx.send('**Invalid url or file.**', delete_after=10) + await ctx.send('**Invalid url or file**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @commands.command(name='reversify', aliases=['revify', 'risify', 'rify']) @@ -333,7 +333,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.NotFound: - await ctx.send('**No matches found.**', delete_after=10) + await ctx.send('**No matches found**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.BoundsError as e: await ctx.send('`{}` **invalid limit.** Query limited to 30'.format(e), delete_after=10) @@ -407,7 +407,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.NotFound: - await ctx.send('**No matches found.**', delete_after=10) + await ctx.send('**No matches found**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.BoundsError as e: await ctx.send('`{}` **invalid limit.** Query limited to 30'.format(e), delete_after=10) @@ -441,8 +441,8 @@ class MsG: post = await scraper.get_post(attachment.url) - await message.channel.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post))) - await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await message.channel.send('**Probable match from** {}\n{}'.format(message.author.display_name, await scraper.get_image(post))) + await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await asyncio.sleep(self.RATE_LIMIT) @@ -475,7 +475,7 @@ class MsG: if not u.tasks['auto_qual']: self.qualitifying = False print('STOPPED : qualitifying #{}'.format(channel.name)) - await channel.send('**Stopped queueing messages for qualitification in** {}**.**'.format(channel.mention), delete_after=5) + await channel.send('**Stopped queueing messages for qualitification in** {}'.format(channel.mention), delete_after=5) @commands.command(name='autoqualitify', aliases=['autoqual']) @commands.has_permissions(manage_channels=True) @@ -490,7 +490,7 @@ class MsG: self.qualitifying = True print('AUTO-QUALITIFYING : #{}'.format(ctx.channel.name)) - await ctx.send('**Auto-qualitifying all images in {}.**'.format(ctx.channel.mention), delete_after=5) + await ctx.send('**Auto-qualitifying all images in** {}'.format(ctx.channel.mention), delete_after=5) await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') else: raise exc.Exists @@ -689,7 +689,7 @@ class MsG: await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) else: - await paginator.edit(content='**First image.**') + await paginator.edit(content='**First image**') except exc.GoTo: await paginator.edit(content='**Enter image number...**') @@ -724,9 +724,9 @@ class MsG: await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) except IndexError: - await paginator.edit(content='**No more images found.**') + await paginator.edit(content='**No more images found**') except exc.NotFound: - await paginator.edit(content='**No more images found.**') + await paginator.edit(content='**No more images found**') else: kwargs = u.get_kwargs(ctx, args) dest, query = kwargs['destination'], kwargs['remaining'] @@ -782,7 +782,7 @@ class MsG: await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) else: - await paginator.edit(content='**First image.**') + await paginator.edit(content='**First image**') except exc.GoTo: await paginator.edit(content='**Enter image number...**') @@ -809,7 +809,7 @@ class MsG: await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) else: - await paginator.edit(content='**Last image.**') + await paginator.edit(content='**Last image**') finally: return hearted @@ -823,25 +823,25 @@ class MsG: except exc.Abort: try: - await paginator.edit(content='**Exited paginator.**') + await paginator.edit(content='**Exited paginator**') except UnboundLocalError: - await dest.send('**Exited paginator.**') + await dest.send('**Exited paginator**') if not hearted: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except asyncio.TimeoutError: try: - await paginator.edit(content='**Paginator timed out.**') + await paginator.edit(content='**Paginator timed out**') except UnboundLocalError: - await dest.send('**Paginator timed out.**') + await dest.send('**Paginator timed out**') if not hearted: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.NotFound: - await ctx.send('**Pool not found.**', delete_after=10) + await ctx.send('**Pool not found**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.Timeout: - await ctx.send('**Request timed out.**') + await ctx.send('**Request timed out**') await ctx.message.add_reaction('\N{CROSS MARK}') finally: @@ -864,34 +864,34 @@ class MsG: except exc.Abort: try: - await paginator.edit(content='**Exited paginator.**') + await paginator.edit(content='**Exited paginator**') except UnboundLocalError: - await dest.send('**Exited paginator.**') + await dest.send('**Exited paginator**') if not hearted: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except asyncio.TimeoutError: try: - await paginator.edit(content='**Paginator timed out.**') + await paginator.edit(content='**Paginator timed out**') except UnboundLocalError: - await dest.send('**Paginator timed out.**') + await dest.send('**Paginator timed out**') if not hearted: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.NotFound as e: - await ctx.send('`{}` **not found.**'.format(e), delete_after=10) + await ctx.send('`{}` **not found**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.TagBlacklisted as e: - await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted.**'.format(e), delete_after=10) + await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{NO ENTRY SIGN}') except exc.TagBoundsError as e: await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.FavoritesNotFound: - await ctx.send('**You have no favorite tags.**', delete_after=10) + await ctx.send('**You have no favorite tags**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.Timeout: - await ctx.send('**Request timed out.**') + await ctx.send('**Request timed out**') await ctx.message.add_reaction('\N{CROSS MARK}') finally: @@ -908,7 +908,7 @@ class MsG: @e621_paginator.error async def e621_paginator_error(self, ctx, error): if isinstance(error, errext.CheckFailure): - await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel.**'.format(ctx.channel.mention), delete_after=10) + await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention), delete_after=10) return await ctx.message.add_reaction('\N{NO ENTRY}') # Searches for and returns images from e621.net given tags when not blacklisted @@ -939,7 +939,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.TagBlacklisted as e: - await ctx.send('`{}` **blacklisted.**'.format(e), delete_after=10) + await ctx.send('`{}` **blacklisted**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.BoundsError as e: await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e), delete_after=10) @@ -948,13 +948,13 @@ class MsG: await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.NotFound as e: - await ctx.send('`{}` **not found.**'.format(e), delete_after=10) + await ctx.send('`{}` **not found**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.FavoritesNotFound: - await ctx.send('**You have no favorite tags.**', delete_after=10) + await ctx.send('**You have no favorite tags**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.Timeout: - await ctx.send('**Request timed out.**') + await ctx.send('**Request timed out**') await ctx.message.add_reaction('\N{CROSS MARK}') # tools.command_dict.setdefault(str(ctx.author.id), {}).update( @@ -963,7 +963,7 @@ class MsG: @e621.error async def e621_error(self, ctx, error): if isinstance(error, errext.CheckFailure): - await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel.**'.format(ctx.channel.mention), delete_after=10) + await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention), delete_after=10) return await ctx.message.add_reaction('\N{NO ENTRY}') # Searches for and returns images from e926.net given tags when not blacklisted @@ -993,7 +993,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.TagBlacklisted as e: - await ctx.send('`{}` **blacklisted.**'.format(e), delete_after=10) + await ctx.send('`{}` **blacklisted**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.BoundsError as e: await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e), delete_after=10) @@ -1002,13 +1002,13 @@ class MsG: await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.NotFound as e: - await ctx.send('`{}` **not found.**'.format(e), delete_after=10) + await ctx.send('`{}` **not found**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.FavoritesNotFound: - await ctx.send('**You have no favorite tags.**', delete_after=10) + await ctx.send('**You have no favorite tags**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.Timeout: - await ctx.send('**Request timed out.**') + await ctx.send('**Request timed out**') await ctx.message.add_reaction('\N{CROSS MARK}') @commands.group(aliases=['fave', 'fav', 'f']) @@ -1063,7 +1063,7 @@ class MsG: await ctx.send('**Favorites list currently limited to:** `5`', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except exc.TagBlacklisted as e: - await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted.**', delete_after=10) + await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted**', delete_after=10) await ctx.message.add_reaction('\N{NO ENTRY SIGN}') @_add_favorite.command(name='posts', aliases=['p']) @@ -1093,7 +1093,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.TagError as e: - await ctx.send('`{}` **not in favorites.**'.format(e), delete_after=10) + await ctx.send('`{}` **not in favorites**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @_remove_favorite.command(name='posts', aliases=['p']) @@ -1112,7 +1112,7 @@ class MsG: del self.favorites[ctx.author.id] u.dump(self.favorites, 'cogs/favorites.pkl') - await dest.send('{}**\'s favorites cleared.**'.format(ctx.author.mention), delete_after=5) + await dest.send('{}**\'s favorites cleared**'.format(ctx.author.mention), delete_after=5) await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') @_clear_favorite.command(name='posts', aliases=['p']) @@ -1130,12 +1130,12 @@ class MsG: # @blacklist.error # async def blacklist_error(self, ctx, error): # if isinstance(error, KeyError): - # return await ctx.send('**Blacklist does not exist.**', delete_after=10) + # return await ctx.send('**Blacklist does not exist**', delete_after=10) @blacklist.group(name='get', aliases=['g']) async def _get_blacklist(self, ctx): if ctx.invoked_subcommand is None: - await ctx.send('**Invalid blacklist.**', delete_after=10) + await ctx.send('**Invalid blacklist**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @_get_blacklist.command(name='global', aliases=['gl', 'g']) @@ -1175,7 +1175,7 @@ class MsG: @_get_blacklist.group(name='all', aliases=['a']) async def __get_all_blacklists(self, ctx): if ctx.invoked_subcommand is None: - await ctx.send('**Invalid blacklist.**') + await ctx.send('**Invalid blacklist**') await ctx.message.add_reaction('\N{CROSS MARK}') @__get_all_blacklists.command(name='guild', aliases=['g']) @@ -1200,7 +1200,7 @@ class MsG: @blacklist.group(name='add', aliases=['a']) async def _add_tags(self, ctx): if ctx.invoked_subcommand is None: - await ctx.send('**Invalid blacklist.**', delete_after=10) + await ctx.send('**Invalid blacklist**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @_add_tags.command(name='global', aliases=['gl', 'g']) @@ -1275,7 +1275,7 @@ class MsG: @blacklist.group(name='remove', aliases=['rm', 'r']) async def _remove_tags(self, ctx): if ctx.invoked_subcommand is None: - await ctx.send('**Invalid blacklist.**', delete_after=10) + await ctx.send('**Invalid blacklist**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @_remove_tags.command(name='global', aliases=['gl', 'g']) @@ -1298,7 +1298,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.TagError as e: - await ctx.send('`{}` **not in blacklist.**'.format(e), delete_after=10) + await ctx.send('`{}` **not in blacklist**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @_remove_tags.command(name='channel', aliases=['ch', 'c']) @@ -1324,7 +1324,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.TagError as e: - await ctx.send('`{}` **not in blacklist.**'.format(e), delete_after=10) + await ctx.send('`{}` **not in blacklist**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @_remove_tags.command(name='me', aliases=['m']) @@ -1346,13 +1346,13 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.TagError as e: - await ctx.send('`{}` **not in blacklist.**'.format(e), delete_after=10) + await ctx.send('`{}` **not in blacklist**'.format(e), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @blacklist.group(name='clear', aliases=['cl', 'c']) async def _clear_blacklist(self, ctx): if ctx.invoked_subcommand is None: - await ctx.send('**Invalid blacklist.**', delete_after=10) + await ctx.send('**Invalid blacklist**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') @_clear_blacklist.command(name='global', aliases=['gl', 'g']) @@ -1363,7 +1363,7 @@ class MsG: self.blacklists['global_blacklist'].clear() u.dump(self.blacklists, 'cogs/blacklists.pkl') - await dest.send('**Global blacklist cleared.**', delete_after=5) + await dest.send('**Global blacklist cleared**', delete_after=5) await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') @_clear_blacklist.command(name='channel', aliases=['ch', 'c']) @@ -1378,7 +1378,7 @@ class MsG: del self.blacklists['guild_blacklist'][guild.id][ctx.channel.id] u.dump(self.blacklists, 'cogs/blacklists.pkl') - await dest.send('{} **blacklist cleared.**'.format(ctx.channel.mention), delete_after=5) + await dest.send('{} **blacklist cleared**'.format(ctx.channel.mention), delete_after=5) await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') @_clear_blacklist.command(name='me', aliases=['m']) @@ -1389,5 +1389,5 @@ class MsG: del self.blacklists['user_blacklist'][ctx.author.id] u.dump(self.blacklists, 'cogs/blacklists.pkl') - await dest.send('{}**\'s blacklist cleared.**'.format(ctx.author.mention), delete_after=5) + await dest.send('{}**\'s blacklist cleared**'.format(ctx.author.mention), delete_after=5) await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') diff --git a/src/main/cogs/management.py b/src/main/cogs/management.py index 5c4733c..7e0d00d 100644 --- a/src/main/cogs/management.py +++ b/src/main/cogs/management.py @@ -50,7 +50,7 @@ class Administration: history = [] try: - pru_sent = await ctx.send('\N{HOURGLASS} **Pruning** <@{}>**\'s messages will take some time.**'.format(user)) + pru_sent = await ctx.send('\N{HOURGLASS} **Pruning** <@{}>**\'s messages will take some time**'.format(user)) ch_sent = await ctx.send('\N{FILE CABINET} **Caching channels...**') if when is None: @@ -58,54 +58,54 @@ class Administration: async for message in channel.history(limit=None): if message.author.id == int(user): history.append(message) - await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) + await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) elif when == 'before': for channel in channels: 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='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) + await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) elif when == 'after': for channel in channels: 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='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) + await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) elif when == 'about': for channel in channels: 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='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) + await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(self.RATE_LIMIT) est_sent = await ctx.send('\N{STOPWATCH} **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) await cont_sent.delete() - del_sent = await ctx.send('\N{WASTEBASKET} **Deleting messages...**') + del_sent = await ctx.send('\N{WASTEBASKET} **Deleting messages..**') await del_sent.pin() c = 0 for message in history: with suppress(err.NotFound): await message.delete() c += 1 - await del_sent.edit(content='\N{WASTEBASKET} **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history))) + await del_sent.edit(content='\N{WASTEBASKET} **Deleted** `{}/{}` **messages**'.format(history.index(message) + 1, len(history))) await asyncio.sleep(self.RATE_LIMIT) await del_sent.unpin() - await ctx.send('\N{WASTEBASKET} `{}` **of** <@{}>**\'s messages left in** {}**.**'.format(len(history) - c, user, ctx.guild.name)) + await ctx.send('\N{WASTEBASKET} `{}` **of** <@{}>**\'s messages left in** {}****'.format(len(history) - c, user, ctx.guild.name)) await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') except exc.CheckFail: - await ctx.send('**Deletion aborted.**', delete_after=10) + await ctx.send('**Deletion aborted**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') except TimeoutError: - await ctx.send('**Deletion timed out.**', delete_after=10) + await ctx.send('**Deletion timed out**', delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') async def delete(self): @@ -143,9 +143,9 @@ class Administration: if not u.tasks['auto_del']: self.deleting = False print('STOPPED : deleting #{}'.format(channel.id)) - await channel.send('**Stopped queueing messages for deletion in** {}**.**'.format(channel.mention), delete_after=5) + await channel.send('**Stopped queueing messages for deletion in** {}'.format(channel.mention), delete_after=5) - @commands.command(name='autodelete', aliases=['autodel', 'ad']) + @commands.command(name='autodelete', aliases=['autodel']) @commands.has_permissions(administrator=True) @checks.del_ctx() async def auto_delete(self, ctx): @@ -158,7 +158,7 @@ class Administration: self.bot.loop.create_task(self.delete()) self.deleting = True print('AUTO-DELETING : #{}'.format(ctx.channel.id)) - await ctx.send('**Auto-deleting all messages in {}.**'.format(ctx.channel.mention), delete_after=5) + await ctx.send('**Auto-deleting all messages in {}**'.format(ctx.channel.mention), delete_after=5) await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') else: raise exc.Exists diff --git a/src/main/cogs/tools.py b/src/main/cogs/tools.py index 64d3852..d613193 100644 --- a/src/main/cogs/tools.py +++ b/src/main/cogs/tools.py @@ -105,11 +105,11 @@ class Utils: print('https://www.youtube.com/watch?v=' + youtube.videos().insert(part='snippet', body={'categoryId': '24', 'title': 'Test'}, media_body=http.MediaFileUpload(temp.name, chunksize=-1))) except exc.InvalidVideoFile as e: - await ctx.send('`' + str(e) + '` **not valid video type.**', delete_after=10) + await ctx.send('`' + str(e) + '` **invalid video type**', delete_after=10) except exc.TooManyAttachments as e: await ctx.send('`' + str(e) + '` **too many attachments.** Only one attachment is permitted to upload.', delete_after=10) except exc.MissingAttachment: - await ctx.send('**Missing attachment.**', delete_after=10) + await ctx.send('**Missing attachment**', delete_after=10) @upload.error async def upload_error(self, ctx, error): diff --git a/src/main/run.py b/src/main/run.py index 44804c3..f81f941 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -84,7 +84,7 @@ async def on_error(error, *args, **kwargs): @bot.event async def on_command_error(ctx, error): if isinstance(error, errext.CheckFailure): - await ctx.send('\N{NO ENTRY} **Insufficient permissions.**', delete_after=10) + await ctx.send('\N{NO ENTRY} **Insufficient permissions**', delete_after=10) await ctx.message.add_reaction('\N{NO ENTRY}') elif isinstance(error, errext.CommandNotFound): print('INVALID COMMAND : {}'.format(error), file=sys.stderr) From 58db7ade4b1fc52843fe71b614c85de8ee5b7102 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 16:29:17 -0400 Subject: [PATCH 10/13] Fixed naming error --- src/main/cogs/booru.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 39e0cbc..0519a6a 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -36,7 +36,7 @@ class MsG: if u.tasks['auto_qual']: for channel in u.tasks['auto_qual']: temp = self.bot.get_channel(channel) - self.bot.loop.create_task(self.qualiqueue_for_qualitification(temp)) + self.bot.loop.create_task(self.queue_for_qualitification(temp)) print('AUTO-QUALITIFYING : #{}'.format(temp.name)) self.bot.loop.create_task(self._qualitify()) self.qualitifying = True @@ -50,13 +50,13 @@ class MsG: # if ctx.channel.id not in u.tasks['auto_post']: # u.tasks['auto_post'].append(ctx.channel.id) # u.dump(u.tasks, 'cogs/tasks.pkl') - # self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel)) + # self.bot.loop.create_task(self.queue_for_qualitification(ctx.channel)) # if not self.qualitifying: # self.bot.loop.create_task(self._qualitify()) # self.qualitifying = True # # print('AUTO-POSTING : #{}'.format(ctx.channel.name)) - # await ctx.send('**Auto-posting all images in {}.**'.format(ctx.channel.mention), delete_after=5) + # await ctx.send('**Auto-posting all images in {}**'.format(ctx.channel.mention), delete_after=5) # await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') # else: # raise exc.Exists @@ -484,7 +484,7 @@ class MsG: if ctx.channel.id not in u.tasks['auto_qual']: u.tasks['auto_qual'].append(ctx.channel.id) u.dump(u.tasks, 'cogs/tasks.pkl') - self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel)) + self.bot.loop.create_task(self.queue_for_qualitification(ctx.channel)) if not self.qualitifying: self.bot.loop.create_task(self._qualitify()) self.qualitifying = True From c6982862fdc1bc15fc55abc68a8648ab7d249106 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 16:30:07 -0400 Subject: [PATCH 11/13] Tweaked command names --- src/main/cogs/booru.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 0519a6a..bcf9263 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -815,7 +815,7 @@ class MsG: return hearted # Creates reaction-based paginator for linked pools - @commands.command(name='poolp', aliases=['e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True) + @commands.command(name='poolpage', aliases=['poolp', 'pp', 'e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True) @checks.del_ctx() async def pool_paginator(self, ctx, *args): try: @@ -855,7 +855,7 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - @commands.command(name='e621p', aliases=['e6p', '6p']) + @commands.command(name='e621page', aliases=['e621p', 'e6p', '6p']) @checks.del_ctx() @checks.is_nsfw() async def e621_paginator(self, ctx, *args): From 0dc968f177b2e048407693737cb3a58ce1721678 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 16:30:46 -0400 Subject: [PATCH 12/13] Fixed naming error --- src/main/cogs/booru.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index bcf9263..0804d62 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -459,7 +459,7 @@ class MsG: def check(msg): if msg.content.lower() == 'stop' and msg.channel is channel and msg.author.guild_permissions.administrator: raise exc.Abort - elif msg.channel is channel and message.author.id != self.bot.user.id and (re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', msg.content) is not None or msg.attachments): + elif msg.channel is channel and msg.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', msg.content) is not None or msg.attachments or msg.embeds): return True return False From 0ebd06c4c16fd37be9f9540f81b217438f155691 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 28 Oct 2017 16:32:04 -0400 Subject: [PATCH 13/13] Compressed history checks into one url loop, failed reaction tweak --- src/main/cogs/booru.py | 142 ++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 86 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 0804d62..4465d09 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -276,44 +276,30 @@ class MsG: kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5) dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit'] urls = [] - attachments = [] + c = 0 if not ctx.author.permissions_in(ctx.channel).manage_messages: dest = ctx.author async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit): - if len(urls) + len(attachments) >= limit: + if c >= limit: break - if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None: - urls.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') - elif message.author.id != self.bot.user.id and message.attachments: - attachments.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + if message.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None or message.embeds or message.attachments): + for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): + urls.append(match.group(0)) + for embed in message.embeds: + if embed.image.url is not d.Embed.Empty: + urls.append(embed.image.url) + for attachment in message.attachments: + urls.append(attachment.url) - if not urls and not attachments: + await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + c += 1 + + if not urls: raise exc.NotFound - for message in urls: - for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): - try: - await dest.trigger_typing() - - await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_post(match.group(0)))) - await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - - await asyncio.sleep(self.RATE_LIMIT) - - if remove: - with suppress(err.NotFound): - await message.delete() - - except exc.MatchError as e: - await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) - await message.add_reaction('\N{CROSS MARK}') - - for message in attachments: - for attachment in message.attachments: + for url in urls: try: await dest.trigger_typing() @@ -322,15 +308,19 @@ class MsG: await asyncio.sleep(self.RATE_LIMIT) - if remove: - with suppress(err.NotFound): - await message.delete() + if remove: + with suppress(err.NotFound): + await message.delete() except exc.MatchError as e: await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) await message.add_reaction('\N{CROSS MARK}') + c -= 1 + if c > 0: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + else: + await ctx.message.add_reaction('\N{CROSS MARK}') except exc.NotFound: await ctx.send('**No matches found**', delete_after=10) @@ -346,65 +336,53 @@ class MsG: kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5) dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit'] urls = [] - attachments = [] + c = 0 if not ctx.author.permissions_in(ctx.channel).manage_messages: dest = ctx.author async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit): - if len(urls) + len(attachments) >= limit: + if c >= limit: break - if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None: - urls.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') - elif message.author.id != self.bot.user.id and message.attachments: - attachments.append(message) - await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + if message.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None or message.embeds or message.attachments): + for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): + urls.append(match.group(0)) + for embed in message.embeds: + if embed.image.url is not d.Embed.Empty: + urls.append(embed.image.url) + for attachment in message.attachments: + urls.append(attachment.url) - if not urls and not attachments: + await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') + c += 1 + + if not urls: raise exc.NotFound - for message in urls: - for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): - try: - await dest.trigger_typing() - - post = await scraper.get_post(match.group(0)) - - await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post))) - await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - - await asyncio.sleep(self.RATE_LIMIT) - - if remove: - with suppress(err.NotFound): - await message.delete() - - except exc.MatchError as e: - await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) - await message.add_reaction('\N{CROSS MARK}') - - for message in attachments: - for attachment in message.attachments: + for url in urls: try: await dest.trigger_typing() - post = await scraper.get_post(attachment.url) + post = await scraper.get_post(url) await dest.send('**Probable match from** {} `{} / {}`\n{}'.format(message.author.display_name, urls.index(url) + 1, len(urls), await scraper.get_image(post))) await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await asyncio.sleep(self.RATE_LIMIT) - if remove: - with suppress(err.NotFound): - await message.delete() + if remove: + with suppress(err.NotFound): + await message.delete() except exc.MatchError as e: await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) await message.add_reaction('\N{CROSS MARK}') + c -= 1 + if c > 0: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + else: + await ctx.message.add_reaction('\N{CROSS MARK}') except exc.NotFound: await ctx.send('**No matches found**', delete_after=10) @@ -416,32 +394,24 @@ class MsG: async def _qualitify(self): while self.qualitifying: message = await self.qualiqueue.get() + urls = [] - for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): - try: - await message.channel.trigger_typing() - - post = await scraper.get_post(match.group(0)) - - await message.channel.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post))) - await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - - await asyncio.sleep(self.RATE_LIMIT) - - with suppress(err.NotFound): - await message.delete() - - except exc.MatchError as e: - await message.channel.send('**No probable match for:** `{}`'.format(e), delete_after=10) - await message.add_reaction('\N{CROSS MARK}') - + for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): + urls.append(match.group(0)) + for embed in message.embeds: + if embed.image.url is not d.Embed.Empty: + urls.append(embed.image.url) for attachment in message.attachments: + urls.append(attachment.url) + + for url in urls: try: await message.channel.trigger_typing() - post = await scraper.get_post(attachment.url) + post = await scraper.get_post(url) await message.channel.send('**Probable match from** {}\n{}'.format(message.author.display_name, await scraper.get_image(post))) + with suppress(err.NotFound): await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await asyncio.sleep(self.RATE_LIMIT)