From 894cbf86871cb72f966d3198ebbd6d3711eff16e Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:38:49 -0400 Subject: [PATCH 01/11] Tweaked UA header --- src/main/utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/utils/utils.py b/src/main/utils/utils.py index c3989ef..6ace555 100644 --- a/src/main/utils/utils.py +++ b/src/main/utils/utils.py @@ -106,7 +106,7 @@ def close(loop): async def fetch(url, *, params={}, json=False): global session - async with session.get(url, params=params, headers={'User-Agent': 'Myned/Modumind/0.0.1'}) as r: + async with session.get(url, params=params, headers={'User-Agent': 'Myned/Modumind/dev'}) as r: if json: return await r.json() return await r.read() From 4faa5b9bb79e92ffac2efed2559077a0baa8f5dd Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:39:11 -0400 Subject: [PATCH 02/11] Whitespace inconsistency --- src/main/utils/scraper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/utils/scraper.py b/src/main/utils/scraper.py index 1c4fabc..32ec51c 100644 --- a/src/main/utils/scraper.py +++ b/src/main/utils/scraper.py @@ -16,6 +16,7 @@ async def get_post(url): return value else: raise IndexError + except IndexError: try: raise exc.MatchError(re.search('\/([^\/]+)$', url).group(1)) From 4528c6fe10f5f81efc46d6ac4c53c7654f4d0c1e Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:40:06 -0400 Subject: [PATCH 03/11] Testing with audit logs --- src/main/run.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/run.py b/src/main/run.py index f908b46..f95296b 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -6,6 +6,7 @@ import subprocess import sys import traceback as tb from contextlib import suppress +from pprint import pprint import discord as d from discord import utils @@ -135,8 +136,13 @@ def after(voice, error): @commands.is_owner() @checks.del_ctx() async def test(ctx): - channel = bot.get_channel(int(cid)) - voice = await channel.connect() - voice.play(d.AudioSource, after=lambda: after(voice)) + logs = [] + async for entry in ctx.guild.audit_logs(limit=None, action=d.AuditLogAction.message_delete): + logs.append( + f'@{entry.user.name} deleted {entry.extra.count} messages from @{entry.target.name} in #{entry.extra.channel.name}') + pprint(logs) + # channel = bot.get_channel(int(cid)) + # voice = await channel.connect() + # voice.play(d.AudioSource, after=lambda: after(voice)) bot.run(u.config['token']) From 04ec3b9955e00b3be7109e4892aed2196f7298dd Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:40:36 -0400 Subject: [PATCH 04/11] Fixed commands not showing in help if checks fail --- src/main/run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/run.py b/src/main/run.py index f95296b..e86f690 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -26,7 +26,8 @@ def get_prefix(bot, message): return u.config['prefix'] -bot = commands.Bot(command_prefix=get_prefix, description='Experimental miscellaneous bot') +bot = commands.Bot(command_prefix=get_prefix, formatter=commands.HelpFormatter( + show_check_failure=True), description='Experimental miscellaneous bot') # Send and print ready message to #testing and console after logon From 3c09863a60c059a9ea992003e2f9894acb25f70c Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:41:01 -0400 Subject: [PATCH 05/11] Error formatting tweak --- src/main/run.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/run.py b/src/main/run.py index e86f690..54244fa 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -69,8 +69,8 @@ async def on_message(message): async def on_error(error, *args, **kwargs): print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr) tb.print_exc() - await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN} `{}`'.format(error)) - await bot.get_channel(u.config['info_channel']).send('**ERROR** \N{WARNING SIGN} `{}`'.format(error)) + await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) + await bot.get_channel(u.config['info_channel']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) if u.temp: channel = bot.get_channel(u.temp['restart_ch']) message = await channel.get_message(u.temp['restart_msg']) @@ -93,8 +93,8 @@ async def on_command_error(ctx, error): print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format( error), file=sys.stderr) tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr) - await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}`'.format(error)) - await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}`'.format(error)) + await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) + await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) await exc.send_error(ctx, error) await ctx.message.add_reaction('\N{WARNING SIGN}') # u.notify('C O M M A N D E R R O R') From 4bd72a160fc869b07201b120b7f26f715329c1c6 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:41:22 -0400 Subject: [PATCH 06/11] WIP endpoint command --- src/main/cogs/owner.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index 19a9718..937ba17 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -212,3 +212,7 @@ class Tools: @debug.command(name='inspect', aliases=['ins']) async def _inspect(self, ctx, *, input_): pass + + # @commands.command(name='endpoint', aliases=['end']) + # async def get_endpoint(self, ctx, *args): + # await ctx.send(f'```\n{await u.fetch(f"https://{args[0]}/{args[1]}/{args[2]}", params={args[3]: args[4], "limit": 1}, json=True)}```') From 0658a62823f2f412de293e7b26995264a3a48d26 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:41:58 -0400 Subject: [PATCH 07/11] Lowered timeout for image position --- 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 1c0ac36..aa4dbb2 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -487,7 +487,7 @@ class MsG: pools.append(pool['name']) match = await ctx.send('**Multiple pools found.** Type in the correct match.\n```\n{}```\nor `cancel` to cancel.'.format('\n'.join(['{} {}'.format(c, elem) for c, elem in enumerate(pools, 1)]))) try: - selection = await self.bot.wait_for('message', check=on_message, timeout=10 * 60) + selection = await self.bot.wait_for('message', check=on_message, timeout=5 * 60) except exc.Abort: raise exc.Abort finally: From 51205c31bc4d9fd79de81d832dbc005e4f53ca32 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:42:32 -0400 Subject: [PATCH 08/11] Changed internal methods to use leading underscores --- 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 aa4dbb2..a87c92c 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -459,7 +459,7 @@ class MsG: await ctx.send('**Already auto-qualitifying in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=10) await ctx.message.add_reaction('\N{CROSS MARK}') - def get_favorites(self, ctx, args): + def _get_favorites(self, ctx, args): if '-f' in args or '-favs' in args or '-faves' in args or '-favorites' in args: if self.favorites.get(ctx.author.id, {}).get('tags', set()): args = ['~{}'.format(tag) for tag in self.favorites[ctx.author.id]['tags']] @@ -468,7 +468,7 @@ class MsG: return args - async def return_pool(self, ctx, *, booru='e621', query=[]): + async def _get_pool(self, ctx, *, booru='e621', query=[]): def on_message(msg): if msg.content.lower() == 'cancel' and msg.author is ctx.author and msg.channel is ctx.channel: raise exc.Abort From 82729dc6c1c0379787196243909d4a5e5ffc330d Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:43:01 -0400 Subject: [PATCH 09/11] Added alias for paginator --- 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 a87c92c..0ae2cf2 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -512,7 +512,7 @@ class MsG: return pool, posts # Creates reaction-based paginator for linked pools - @commands.command(name='pool', aliases=['e6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True) + @commands.command(name='pool', aliases=['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): def on_reaction(reaction, user): From f96b5270c90fee0c578b1cc898da4def0ffdee6d Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:44:05 -0400 Subject: [PATCH 10/11] Added redundant check for image position input (> 0) --- 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 0ae2cf2..3a58e0e 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -530,7 +530,7 @@ class MsG: def on_message(msg): if msg.content.isdigit(): - if int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel: + if 1 <= int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel: return True return False @@ -692,9 +692,9 @@ class MsG: posts[post['id']] = {'author': post['author'], 'url': post['file_url']} if len(posts) == limit: break - c += 1 + c += 1 - return posts + return posts @commands.command(name='e621p', aliases=['e6p', '6p']) @checks.del_ctx() @@ -715,7 +715,7 @@ class MsG: def on_message(msg): if msg.content.isdigit(): - if int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel: + if 1 <= int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel: return True return False From f121ccd3f8e9f75e953c6dc42c451163fbcd42a1 Mon Sep 17 00:00:00 2001 From: Myned Date: Sat, 21 Oct 2017 16:45:26 -0400 Subject: [PATCH 11/11] Removed owner global access to paginator, starred > hearted, ordering --- src/main/cogs/booru.py | 225 +++++++++++++++++++++++------------------ 1 file changed, 126 insertions(+), 99 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 3a58e0e..8303be9 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -516,15 +516,15 @@ class MsG: @checks.del_ctx() async def pool_paginator(self, ctx, *args): def on_reaction(reaction, user): - if reaction.emoji == '\N{OCTAGONAL SIGN}' and reaction.message.id == ctx.message.id and (user is ctx.author or user.id == u.config['owner_id']): + if reaction.emoji == '\N{OCTAGONAL SIGN}' and reaction.message.id == ctx.message.id and user is ctx.author: raise exc.Abort - elif reaction.emoji == '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): - raise exc.GoTo - elif reaction.emoji == '\N{LEFTWARDS BLACK ARROW}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): - raise exc.Left - elif reaction.emoji == '\N{GROWING HEART}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): + elif reaction.emoji == '\N{GROWING HEART}' and reaction.message.id == paginator.id and user is ctx.author: raise exc.Save - elif reaction.emoji == '\N{BLACK RIGHTWARDS ARROW}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): + elif reaction.emoji == '\N{LEFTWARDS BLACK ARROW}' and reaction.message.id == paginator.id and user is ctx.author: + raise exc.Left + elif reaction.emoji == '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}' and reaction.message.id == paginator.id and user is ctx.author: + raise exc.GoTo + elif reaction.emoji == '\N{BLACK RIGHTWARDS ARROW}' and reaction.message.id == paginator.id and user is ctx.author: raise exc.Right return False @@ -537,12 +537,12 @@ class MsG: try: kwargs = u.get_kwargs(ctx, args) dest, query = kwargs['destination'], kwargs['remaining'] - starred = [] + hearted = [] c = 1 await dest.trigger_typing() - pool, posts = await self.return_pool(ctx, booru='e621', query=query) + pool, posts = await self._get_pool(ctx, booru='e621', query=query) keys = list(posts.keys()) values = list(posts.values()) @@ -556,7 +556,7 @@ class MsG: paginator = await dest.send(embed=embed) - for emoji in ('\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{LEFTWARDS BLACK ARROW}', '\N{GROWING HEART}', '\N{BLACK RIGHTWARDS ARROW}'): + for emoji in ('\N{GROWING HEART}', '\N{LEFTWARDS BLACK ARROW}', '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{BLACK RIGHTWARDS ARROW}'): await paginator.add_reaction(emoji) await ctx.message.add_reaction('\N{OCTAGONAL SIGN}') await asyncio.sleep(1) @@ -568,6 +568,29 @@ class MsG: for future in done: future.result() + except exc.Save: + if values[c - 1]['url'] not in hearted: + hearted.append(values[c - 1]['url']) + + await paginator.edit(content='\N{HEAVY BLACK HEART}') + else: + hearted.remove(values[c - 1]['url']) + + await paginator.edit(content='\N{BROKEN HEART}') + + except exc.Left: + if c > 1: + c -= 1 + embed.title = values[c - 1]['author'] + embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) + embed.set_footer(text='{} / {}'.format(c, len(posts)), + icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_image(url=values[c - 1]['url']) + + 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.**') + except exc.GoTo: await paginator.edit(content='**Enter image number...**') number = await self.bot.wait_for('message', check=on_message, timeout=10 * 60) @@ -580,30 +603,7 @@ class MsG: icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') embed.set_image(url=values[c - 1]['url']) - await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in starred else None, embed=embed) - - except exc.Left: - if c > 1: - c -= 1 - embed.title = values[c - 1]['author'] - embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') - embed.set_image(url=values[c - 1]['url']) - - await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in starred else None, embed=embed) - else: - await paginator.edit(content='**First image.**') - - except exc.Save: - if values[c - 1]['url'] not in starred: - starred.append(values[c - 1]['url']) - - await paginator.edit(content='\N{HEAVY BLACK HEART}') - else: - starred.remove(values[c - 1]['url']) - - await paginator.edit(content='\N{BROKEN HEART}') + await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) except exc.Right: if c < len(keys): @@ -614,7 +614,9 @@ class MsG: icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') embed.set_image(url=values[c - 1]['url']) - await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in starred else None, embed=embed) + 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.**') except exc.Abort: try: @@ -622,12 +624,16 @@ class MsG: except UnboundLocalError: 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.**') except UnboundLocalError: 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.message.add_reaction('\N{CROSS MARK}') @@ -636,18 +642,18 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') finally: - if starred: + if hearted: await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') - for url in starred: - await ctx.author.send('`{} / {}`\n{}'.format(starred.index(url) + 1, len(starred), url)) - if len(starred) > 5: - await asyncio.sleep(self.RATE_LIMIT) + for url in hearted: + await ctx.author.send('`{} / {}`\n{}'.format(hearted.index(url) + 1, len(hearted), url)) - await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await asyncio.sleep(self.RATE_LIMIT) + + await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') # Messy code that checks image limit and tags in blacklists - async def check_return_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}): + async def _get_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}): guild = ctx.guild if isinstance( ctx.guild, d.Guild) else ctx.channel @@ -669,6 +675,8 @@ class MsG: # Checks for blacklisted tags in endpoint blacklists - try/except is for continuing the parent loop posts = {} + temposts = len(posts) + empty = 0 c = 0 while len(posts) < limit: if c == limit * 5 + self.LIMIT: @@ -692,24 +700,35 @@ class MsG: posts[post['id']] = {'author': post['author'], 'url': post['file_url']} if len(posts) == limit: break + + if len(posts) == temposts: + empty += 1 + if empty == 5: + break + else: + empty = 0 + temposts = len(posts) c += 1 + if posts: return posts + else: + raise exc.NotFound @commands.command(name='e621p', aliases=['e6p', '6p']) @checks.del_ctx() @checks.is_nsfw() async def e621_paginator(self, ctx, *args): def on_reaction(reaction, user): - if reaction.emoji == '\N{OCTAGONAL SIGN}' and reaction.message.id == ctx.message.id and (user is ctx.author or user.id == u.config['owner_id']): + if reaction.emoji == '\N{OCTAGONAL SIGN}' and reaction.message.id == ctx.message.id and user is ctx.author: raise exc.Abort - elif reaction.emoji == '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): - raise exc.GoTo - elif reaction.emoji == '\N{LEFTWARDS BLACK ARROW}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): - raise exc.Left - elif reaction.emoji == '\N{GROWING HEART}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): + elif reaction.emoji == '\N{GROWING HEART}' and reaction.message.id == paginator.id and user is ctx.author: raise exc.Save - elif reaction.emoji == '\N{BLACK RIGHTWARDS ARROW}' and reaction.message.id == paginator.id and (user is ctx.author or user.id == u.config['owner_id']): + elif reaction.emoji == '\N{LEFTWARDS BLACK ARROW}' and reaction.message.id == paginator.id and user is ctx.author: + raise exc.Left + elif reaction.emoji == '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}' and reaction.message.id == paginator.id and user is ctx.author: + raise exc.GoTo + elif reaction.emoji == '\N{BLACK RIGHTWARDS ARROW}' and reaction.message.id == paginator.id and user is ctx.author: raise exc.Right return False @@ -723,14 +742,14 @@ class MsG: kwargs = u.get_kwargs(ctx, args) dest, tags = kwargs['destination'], kwargs['remaining'] limit = self.LIMIT / 5 - starred = [] + hearted = [] c = 1 - tags = self.get_favorites(ctx, tags) + tags = self._get_favorites(ctx, tags) await ctx.trigger_typing() - posts = await self.check_return_posts(ctx, booru='e621', tags=tags, limit=limit) + posts = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) keys = list(posts.keys()) values = list(posts.values()) @@ -744,7 +763,7 @@ class MsG: paginator = await dest.send(embed=embed) - for emoji in ('\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{LEFTWARDS BLACK ARROW}', '\N{GROWING HEART}', '\N{BLACK RIGHTWARDS ARROW}'): + for emoji in ('\N{GROWING HEART}', '\N{LEFTWARDS BLACK ARROW}', '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{BLACK RIGHTWARDS ARROW}'): await paginator.add_reaction(emoji) await ctx.message.add_reaction('\N{OCTAGONAL SIGN}') await asyncio.sleep(1) @@ -756,6 +775,29 @@ class MsG: for future in done: future.result() + except exc.Save: + if values[c - 1]['url'] not in hearted: + hearted.append(values[c - 1]['url']) + + await paginator.edit(content='\N{HEAVY BLACK HEART}') + else: + hearted.remove(values[c - 1]['url']) + + await paginator.edit(content='\N{BROKEN HEART}') + + except exc.Left: + if c > 1: + c -= 1 + embed.title = values[c - 1]['author'] + embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) + embed.set_footer(text='{} / {}'.format(c, len(posts)), + icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_image(url=values[c - 1]['url']) + + 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.**') + except exc.GoTo: await paginator.edit(content='**Enter image number...**') number = await self.bot.wait_for('message', check=on_message, timeout=10 * 60) @@ -768,49 +810,30 @@ class MsG: icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') embed.set_image(url=values[c - 1]['url']) - await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in starred else None, embed=embed) + await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) - except exc.Left: - if c > 1: - c -= 1 + except exc.Right: + try: + if c % limit == 0: + await dest.trigger_typing() + posts.update(await self._get_posts(ctx, booru='e621', tags=tags, limit=limit, previous=posts)) + + keys = list(posts.keys()) + values = list(posts.values()) + + c += 1 embed.title = values[c - 1]['author'] embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) embed.set_footer(text='{} / {}'.format(c, len(posts)), icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') embed.set_image(url=values[c - 1]['url']) - await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in starred else None, embed=embed) - else: - await paginator.edit(content='**First image.**') - except exc.Save: - if values[c - 1]['url'] not in starred: - starred.append(values[c - 1]['url']) + await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) - await paginator.edit(content='\N{HEAVY BLACK HEART}') - else: - starred.remove(values[c - 1]['url']) - - await paginator.edit(content='\N{BROKEN HEART}') - - except exc.Right: - if c % limit == 0: - await dest.trigger_typing() - try: - posts.update(await self.check_return_posts(ctx, booru='e621', tags=tags, limit=limit, previous=posts)) - - except exc.NotFound: - await paginator.edit(content='**No more images found.**') - - keys = list(posts.keys()) - values = list(posts.values()) - - c += 1 - embed.title = values[c - 1]['author'] - embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') - embed.set_image(url=values[c - 1]['url']) - await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in starred else None, embed=embed) + except IndexError: + await paginator.edit(content='**No more images found.**') + except exc.NotFound: + await paginator.edit(content='**No more images found.**') except exc.Abort: try: @@ -818,12 +841,16 @@ class MsG: except UnboundLocalError: 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.**') except UnboundLocalError: 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.message.add_reaction('\N{CROSS MARK}') @@ -831,7 +858,7 @@ class MsG: 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, currently.'.format(e), delete_after=10) + 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) @@ -841,15 +868,15 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') finally: - if starred: + if hearted: await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') - for url in starred: - await ctx.author.send('`{} / {}`\n{}'.format(starred.index(url) + 1, len(starred), url)) - if len(starred) > 5: - await asyncio.sleep(self.RATE_LIMIT) + for url in hearted: + await ctx.author.send('`{} / {}`\n{}'.format(hearted.index(url) + 1, len(hearted), url)) - await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await asyncio.sleep(self.RATE_LIMIT) + + await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') @e621_paginator.error async def e621_paginator_error(self, ctx, error): @@ -866,11 +893,11 @@ class MsG: kwargs = u.get_kwargs(ctx, args, limit=3) dest, args, limit = kwargs['destination'], kwargs['remaining'], kwargs['limit'] - tags = self.get_favorites(ctx, args) + tags = self._get_favorites(ctx, args) await dest.trigger_typing() - posts = await self.check_return_posts(ctx, booru='e621', tags=tags, limit=limit) + posts = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) for ident, post in posts.items(): embed = d.Embed(title=post['author'], url='https://e621.net/post/show/{}'.format(ident), @@ -920,11 +947,11 @@ class MsG: kwargs = u.get_kwargs(ctx, args, limit=3) dest, args, limit = kwargs['destination'], kwargs['remaining'], kwargs['limit'] - tags = self.get_favorites(ctx, args) + tags = self._get_favorites(ctx, args) await dest.trigger_typing() - posts = await self.check_return_posts(ctx, booru='e926', tags=tags, limit=limit) + posts = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit) for ident, post in posts.items(): embed = d.Embed(title=post['author'], url='https://e926.net/post/show/{}'.format(ident),