From dc0142a29e7f0a2aef4a0628ea030492309048ac Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 19 Feb 2019 23:06:52 -0500 Subject: [PATCH 1/7] Remove OS-dependent notifications --- src/cogs/owner.py | 2 -- src/run.py | 3 +-- src/utils/utils.py | 5 ----- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/cogs/owner.py b/src/cogs/owner.py index 578e9d6..8129593 100644 --- a/src/cogs/owner.py +++ b/src/cogs/owner.py @@ -37,7 +37,6 @@ class Bot: # for task in loop: # task.cancel() print('\n< < < < < < < < < < < <\nD I S C O N N E C T E D\n< < < < < < < < < < < <\n') - # u.notify('D I S C O N N E C T E D') await self.bot.logout() @cmds.command(name=',restart', aliases=[',res', ',r'], hidden=True) @@ -47,7 +46,6 @@ class Bot: print('\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^\nR E S T A R T I N G\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^\n') await self.bot.get_channel(u.config['info_channel']).send('**Restarting** \N{SLEEPING SYMBOL} . . .') - # u.notify('R E S T A R T I N G') chantype = 'guild' if isinstance(ctx.channel, d.TextChannel) else 'private' u.temp['startup'] = (chantype, ctx.channel.id if chantype == 'guild' else ctx.author.id, ctx.message.id) diff --git a/src/run.py b/src/run.py index 2d1c7c7..7d79677 100644 --- a/src/run.py +++ b/src/run.py @@ -156,7 +156,7 @@ async def on_error(error, *args, **kwargs): u.temp.clear() u.dump(u.temp, 'temp/temp.pkl') - # u.notify('E R R O R') + await bot.logout() @@ -191,7 +191,6 @@ async def on_command_error(ctx, error): await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.name, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) await exc.send_error(ctx, error) await u.add_reaction(ctx.message, '\N{WARNING SIGN}') - # u.notify('C O M M A N D E R R O R') # @bot.event # async def on_command(ctx): diff --git a/src/utils/utils.py b/src/utils/utils.py index 04fb8d7..7808eb7 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -20,11 +20,6 @@ from misc import exceptions as exc print('\nPID : {}\n'.format(os.getpid())) -# def notify(message): -# subprocess.run(['terminal-notifier', '-message', message, '-title', -# 'Modumind', '-activate', 'com.apple.Terminal', '-appIcon', 'icon.png', '-sound', 'Ping'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - try: with open('config.json') as infile: config = jsn.load(infile) From 08a9d28739744ed41330bf566374a782d764fbbc Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 19 Feb 2019 23:07:31 -0500 Subject: [PATCH 2/7] Remove info_channel --- src/cogs/owner.py | 3 --- src/run.py | 4 ---- src/utils/utils.py | 2 +- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/cogs/owner.py b/src/cogs/owner.py index 8129593..90691f2 100644 --- a/src/cogs/owner.py +++ b/src/cogs/owner.py @@ -27,8 +27,6 @@ class Bot: async def die(self, ctx): await u.add_reaction(ctx.message, '\N{CRESCENT MOON}') - await self.bot.get_channel(u.config['info_channel']).send('**Shutting down** \N{CRESCENT MOON} . . .') - chantype = 'guild' if isinstance(ctx.channel, d.TextChannel) else 'private' u.temp['startup'] = (chantype, ctx.channel.id if chantype == 'guild' else ctx.author.id, ctx.message.id) u.dump(u.temp, 'temp/temp.pkl') @@ -45,7 +43,6 @@ class Bot: await u.add_reaction(ctx.message, '\N{SLEEPING SYMBOL}') print('\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^\nR E S T A R T I N G\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^\n') - await self.bot.get_channel(u.config['info_channel']).send('**Restarting** \N{SLEEPING SYMBOL} . . .') chantype = 'guild' if isinstance(ctx.channel, d.TextChannel) else 'private' u.temp['startup'] = (chantype, ctx.channel.id if chantype == 'guild' else ctx.author.id, ctx.message.id) diff --git a/src/run.py b/src/run.py index 7d79677..29f9ff6 100644 --- a/src/run.py +++ b/src/run.py @@ -87,8 +87,6 @@ async def on_ready(): print('\n> > > > > > > > >\nC O N N E C T E D : {}\n> > > > > > > > >\n'.format(bot.user.name)) try: - await bot.get_channel(u.config['info_channel']).send(f'**Started** \N{BLACK SUN WITH RAYS} `{"` or `".join(u.config["prefix"])}`') - if u.temp['startup']: with suppress(err.NotFound): if u.temp['startup'][0] == 'guild': @@ -142,7 +140,6 @@ async def on_error(error, *args, **kwargs): print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(sys.exc_info()[1].text), file=sys.stderr) tb.print_exc() 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['startup']: with suppress(err.NotFound): @@ -188,7 +185,6 @@ async def on_command_error(ctx, error): 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} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.mention, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) - await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.name, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) await exc.send_error(ctx, error) await u.add_reaction(ctx.message, '\N{WARNING SIGN}') diff --git a/src/utils/utils.py b/src/utils/utils.py index 7808eb7..6302d11 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -27,7 +27,7 @@ try: except FileNotFoundError: with open('config.json', 'w') as outfile: - jsn.dump({'client_id': 0, 'info_channel': 0, 'owner_id': 0, 'permissions': 126016, + jsn.dump({'client_id': 0, 'owner_id': 0, 'permissions': 126016, 'playing': 'a game', 'prefix': [',', 'm,'], 'selfbot': False, 'token': 'str'}, outfile, indent=4, sort_keys=True) print('FILE NOT FOUND : config.json created with abstract values. Restart run.py with correct values') From 44dca56fd0182b8ef0bb07070cf2b900f1628476 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 19 Feb 2019 23:09:01 -0500 Subject: [PATCH 3/7] Remove unnecessary exit logic --- src/run.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/run.py b/src/run.py index 29f9ff6..7794cad 100644 --- a/src/run.py +++ b/src/run.py @@ -142,15 +142,6 @@ async def on_error(error, *args, **kwargs): await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) if u.temp['startup']: - with suppress(err.NotFound): - if u.temp['startup'][0] == 'guild': - ctx = bot.get_channel(u.temp['startup'][1]) - else: - ctx = bot.get_user(u.temp['startup'][1]) - message = await ctx.get_message(u.temp['startup'][2]) - - await message.add_reaction('\N{WARNING SIGN}') - u.temp.clear() u.dump(u.temp, 'temp/temp.pkl') From 073127c789d76a192d5964ab8bf3edaa46b52c27 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 19 Feb 2019 23:09:32 -0500 Subject: [PATCH 4/7] Add back ignoring of command errors --- src/run.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/run.py b/src/run.py index 7794cad..2dab1bc 100644 --- a/src/run.py +++ b/src/run.py @@ -153,6 +153,8 @@ async def on_command_error(ctx, error): with suppress(err.NotFound): if isinstance(error, err.NotFound): print('NOT FOUND') + elif isinstance(error, errext.CommandInvokeError): + print(f'ERROR : {error}') elif isinstance(error, err.Forbidden): pass elif isinstance(error, errext.CommandOnCooldown): From 7b9a62af45972b28fa183fc6587e24be2d3b5af4 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 19 Feb 2019 23:09:57 -0500 Subject: [PATCH 5/7] Change formatting --- src/run.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/run.py b/src/run.py index 2dab1bc..074bef4 100644 --- a/src/run.py +++ b/src/run.py @@ -158,9 +158,9 @@ async def on_command_error(ctx, error): elif isinstance(error, err.Forbidden): pass elif isinstance(error, errext.CommandOnCooldown): - await u.add_reaction(ctx.message, '\N{HOURGLASS}') - await asyncio.sleep(error.retry_after) - await u.add_reaction(ctx.message, '\N{WHITE HEAVY CHECK MARK}') + await u.add_reaction(ctx.message, '\N{HOURGLASS}') + await asyncio.sleep(error.retry_after) + await u.add_reaction(ctx.message, '\N{WHITE HEAVY CHECK MARK}') elif isinstance(error, errext.MissingRequiredArgument): await ctx.send('**Missing required argument**') await u.add_reaction(ctx.message, '\N{CROSS MARK}') @@ -174,8 +174,7 @@ async def on_command_error(ctx, error): print('INVALID COMMAND : {}'.format(error), file=sys.stderr) await u.add_reaction(ctx.message, '\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) + 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} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.mention, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) await exc.send_error(ctx, error) From 0b12630d06894bcf26faad6dea2fa61f9d9b9aec Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 19 Feb 2019 23:10:19 -0500 Subject: [PATCH 6/7] Change heart queue timeout to 24 hours --- src/cogs/booru.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 5f9bb4d..7049a68 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -137,7 +137,7 @@ class MsG: print('STOPPED : hearting') - async def queue_for_hearts(self, *, message=None, send=None, channel=None, reaction=True, timeout=60 * 60): + async def queue_for_hearts(self, *, message=None, send=None, channel=None, reaction=True, timeout=60 * 60 * 24): def on_reaction(reaction, user): if reaction.emoji == '\N{HEAVY BLACK HEART}' and reaction.message.id == message.id and not user.bot: raise exc.Save(user) From 739449b9400bd56a46d2035d34e41bae49e18ca6 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 19 Feb 2019 23:14:36 -0500 Subject: [PATCH 7/7] Change image paginators to use one method and remove GoTo for non-pools --- src/cogs/booru.py | 301 +++++++--------------------------------------- 1 file changed, 42 insertions(+), 259 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 7049a68..f23b954 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -868,10 +868,7 @@ class MsG: await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed) n += 1 - @cmds.command(name='e621page', aliases=['e621p', 'e6p', '6p']) - @checks.is_nsfw() - @cmds.cooldown(1, 5, cmds.BucketType.member) - async def e621_paginator(self, ctx, *args): + async def _get_paginator(self, ctx, args, booru='e621'): 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.permissions_in(reaction.message.channel).manage_messages): raise exc.Abort @@ -879,8 +876,6 @@ class MsG: raise exc.Save 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 @@ -899,21 +894,21 @@ class MsG: await ctx.trigger_typing() - posts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) + posts, order = await self._get_posts(ctx, booru=booru, tags=tags, limit=limit) keys = list(posts.keys()) values = list(posts.values()) embed = d.Embed( - title=values[c - 1]['artist'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) + title=values[c - 1]['artist'], url='https://{}.net/post/show/{}'.format(booru, keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) embed.set_image(url=values[c - 1]['file_url']) embed.set_author(name=' '.join(tags) if tags else order, - url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) + url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url) embed.set_footer(text=values[c - 1]['score'], icon_url=self._get_score(values[c - 1]['score'])) paginator = await ctx.send(embed=embed) - for emoji in ('\N{HEAVY BLACK HEART}', '\N{LEFTWARDS BLACK ARROW}', '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{BLACK RIGHTWARDS ARROW}'): + for emoji in ('\N{HEAVY BLACK HEART}', '\N{LEFTWARDS BLACK ARROW}', '\N{BLACK RIGHTWARDS ARROW}'): await paginator.add_reaction(emoji) await u.add_reaction(ctx.message, '\N{OCTAGONAL SIGN}') await asyncio.sleep(1) @@ -937,7 +932,8 @@ class MsG: if c > 1: c -= 1 embed.title = values[c - 1]['artist'] - embed.url = 'https://e621.net/post/show/{}'.format( + embed.url = 'https://{}.net/post/show/{}'.format( + booru, keys[c - 1]) embed.set_footer(text=values[c - 1]['score'], icon_url=self._get_score(values[c - 1]['score'])) @@ -947,31 +943,11 @@ class MsG: else: await paginator.edit(content='\N{BLACK RIGHTWARDS ARROW}') - except exc.GoTo: - await paginator.edit(content=f'`{c} / {len(posts)}`') - number = await self.bot.wait_for('message', check=on_message, timeout=8*60) - - if int(number.content) != 0: - c = int(number.content) - - embed.title = values[c - 1]['artist'] - embed.url = 'https://e621.net/post/show/{}'.format( - keys[c - 1]) - embed.set_footer(text=values[c - 1]['score'], - icon_url=self._get_score(values[c - 1]['score'])) - embed.set_image(url=values[c - 1]['file_url']) - - if ctx.channel is d.TextChannel: - with suppress(errext.CheckFailure): - await number.delete() - - await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) - except exc.Right: try: if c % limit == 0: await ctx.trigger_typing() - temposts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit, previous=posts) + temposts, order = await self._get_posts(ctx, booru=booru, tags=tags, limit=limit, previous=posts) posts.update(temposts) keys = list(posts.keys()) @@ -980,7 +956,8 @@ class MsG: if c < len(keys): c += 1 embed.title = values[c - 1]['artist'] - embed.url = 'https://e621.net/post/show/{}'.format( + embed.url = 'https://{}.net/post/show/{}'.format( + booru, keys[c - 1]) embed.set_footer(text=values[c - 1]['score'], icon_url=self._get_score(values[c - 1]['score'])) @@ -1028,153 +1005,54 @@ class MsG: await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed) n += 1 - # @e621_paginator.error - # async def e621_paginator_error(self, ctx, error): - # if isinstance(error, exc.NSFW): - # await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention)) - # await u.add_reaction(ctx.message, '\N{NO ENTRY}') + @cmds.command(name='e621page', aliases=['e621p', 'e6p', '6p']) + @checks.is_nsfw() + @cmds.cooldown(1, 5, cmds.BucketType.member) + async def e621_paginator(self, ctx, *args): + await self._get_paginator(ctx, args, booru='e621') + @cmds.command(name='e926page', aliases=['e926p', 'e9p', '9p']) @cmds.cooldown(1, 5, cmds.BucketType.member) async def e926_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.permissions_in(reaction.message.channel).manage_messages): - raise exc.Abort - elif reaction.emoji == '\N{HEAVY BLACK HEART}' and reaction.message.id == paginator.id and user is ctx.author: - raise exc.Save - 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 - - def on_message(msg): - return msg.content.isdigit() and 0 <= int(msg.content) <= len(posts) and msg.author is ctx.author and msg.channel is ctx.channel + await self._get_paginator(ctx, args, booru='e926') + async def _get_images(self, ctx, args, booru='e621'): try: - kwargs = u.get_kwargs(ctx, args) - tags = kwargs['remaining'] - limit = self.LIMIT / 5 - hearted = {} - c = 1 + kwargs = u.get_kwargs(ctx, args, limit=3) + args, limit = kwargs['remaining'], kwargs['limit'] - tags = self._get_favorites(ctx, tags) + tags = self._get_favorites(ctx, args) await ctx.trigger_typing() - posts, order = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit) - keys = list(posts.keys()) - values = list(posts.values()) + posts, order = await self._get_posts(ctx, booru=booru, tags=tags, limit=limit) - embed = d.Embed( - title=values[c - 1]['artist'], url='https://e926.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) - embed.set_image(url=values[c - 1]['file_url']) - embed.set_author(name=' '.join(tags) if tags else order, - url='https://e926.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) - embed.set_footer(text=values[c - 1]['score'], - icon_url=self._get_score(values[c - 1]['score'])) + for ident, post in posts.items(): + embed = d.Embed(title=post['artist'], url='https://{}.net/post/show/{}'.format(booru, ident), + color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) + embed.set_image(url=post['file_url']) + embed.set_author(name=' '.join(tags) if tags else order, + url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url) + embed.set_footer( + text=post['score'], icon_url=self._get_score(post['score'])) - paginator = await ctx.send(embed=embed) + message = await ctx.send(embed=embed) - for emoji in ('\N{HEAVY BLACK HEART}', '\N{LEFTWARDS BLACK ARROW}', '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{BLACK RIGHTWARDS ARROW}'): - await paginator.add_reaction(emoji) - await u.add_reaction(ctx.message, '\N{OCTAGONAL SIGN}') - await asyncio.sleep(1) + self.bot.loop.create_task(self.queue_for_hearts(message=message, send=embed)) - while not self.bot.is_closed(): - try: - await asyncio.gather(*[self.bot.wait_for('reaction_add', check=on_reaction, timeout=8*60), - self.bot.wait_for('reaction_remove', check=on_reaction, timeout=8*60)]) - - except exc.Save: - if keys[c - 1] not in hearted: - hearted[keys[c - 1]] = copy.deepcopy(embed) - - await paginator.edit(content='\N{HEAVY BLACK HEART}') - else: - del hearted[keys[c - 1]] - - await paginator.edit(content='\N{BROKEN HEART}') - - except exc.Left: - if c > 1: - c -= 1 - embed.title = values[c - 1]['artist'] - embed.url = 'https://e926.net/post/show/{}'.format( - keys[c - 1]) - embed.set_footer(text=values[c - 1]['score'], - icon_url=self._get_score(values[c - 1]['score'])) - embed.set_image(url=values[c - 1]['file_url']) - - await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) - else: - await paginator.edit(content='\N{BLACK RIGHTWARDS ARROW}') - - except exc.GoTo: - await paginator.edit(content=f'`{c} / {len(posts)}`') - number = await self.bot.wait_for('message', check=on_message, timeout=8*60) - - if int(number.content) != 0: - c = int(number.content) - - embed.title = values[c - 1]['artist'] - embed.url = 'https://e926.net/post/show/{}'.format( - keys[c - 1]) - embed.set_footer(text=values[c - 1]['score'], - icon_url=self._get_score(values[c - 1]['score'])) - embed.set_image(url=values[c - 1]['file_url']) - - await number.delete() - - await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) - - except exc.Right: - try: - if c % limit == 0: - await ctx.trigger_typing() - temposts, order = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit, previous=posts) - posts.update(temposts) - - keys = list(posts.keys()) - values = list(posts.values()) - - if c < len(keys): - c += 1 - embed.title = values[c - 1]['artist'] - embed.url = 'https://e926.net/post/show/{}'.format( - keys[c - 1]) - embed.set_footer(text=values[c - 1]['score'], - icon_url=self._get_score(values[c - 1]['score'])) - embed.set_image(url=values[c - 1]['file_url']) - - await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) - else: - await paginator.edit(content='\N{LEFTWARDS BLACK ARROW}') - - except exc.NotFound: - await paginator.edit(content='\N{LEFTWARDS BLACK ARROW}') - - except exc.Abort: - try: - await paginator.edit(content='\N{WHITE HEAVY CHECK MARK}') - except UnboundLocalError: - await ctx.send('\N{WHITE HEAVY CHECK MARK}') - except asyncio.TimeoutError: - try: - await paginator.edit(content='\N{HOURGLASS}') - except UnboundLocalError: - await ctx.send('\N{HOURGLASS}') - except exc.NotFound as e: - await ctx.send('`{}` **not found**'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') except exc.TagBlacklisted as e: - await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted**'.format(e)) - await u.add_reaction(ctx.message, '\N{NO ENTRY SIGN}') + await ctx.send('`{}` **blacklisted**'.format(e)) + await u.add_reaction(ctx.message, '\N{CROSS MARK}') + except exc.BoundsError as e: + await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e)) + await u.add_reaction(ctx.message, '\N{CROSS MARK}') except exc.TagBoundsError as e: await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e)) await u.add_reaction(ctx.message, '\N{CROSS MARK}') + except exc.NotFound as e: + await ctx.send('`{}` **not found**'.format(e)) + await u.add_reaction(ctx.message, '\N{CROSS MARK}') except exc.FavoritesNotFound: await ctx.send('**You have no favorite tags**') await u.add_reaction(ctx.message, '\N{CROSS MARK}') @@ -1182,113 +1060,18 @@ class MsG: await ctx.send('**Request timed out**') await u.add_reaction(ctx.message, '\N{CROSS MARK}') - finally: - if hearted: - await u.add_reaction(ctx.message, '\N{HOURGLASS WITH FLOWING SAND}') - - n = 1 - for embed in hearted.values(): - await ctx.author.send(content=f'`{n} / {len(hearted)}`', embed=embed) - n += 1 - # Searches for and returns images from e621.net given tags when not blacklisted @cmds.command(aliases=['e6', '6'], brief='e621 | NSFW', description='e621 | NSFW\nTag-based search for e621.net\n\nYou can only search 5 tags and 6 images at once for now.\ne6 [tags...] ([# of images])') @checks.is_nsfw() @cmds.cooldown(1, 5, cmds.BucketType.member) async def e621(self, ctx, *args): - try: - kwargs = u.get_kwargs(ctx, args, limit=3) - args, limit = kwargs['remaining'], kwargs['limit'] - - tags = self._get_favorites(ctx, args) - - await ctx.trigger_typing() - - posts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) - - for ident, post in posts.items(): - embed = d.Embed(title=post['artist'], url='https://e621.net/post/show/{}'.format(ident), - color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) - embed.set_image(url=post['file_url']) - embed.set_author(name=' '.join(tags) if tags else order, - url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) - embed.set_footer( - text=post['score'], icon_url=self._get_score(post['score'])) - - message = await ctx.send(embed=embed) - - self.bot.loop.create_task(self.queue_for_hearts(message=message, send=embed)) - - except exc.TagBlacklisted as e: - await ctx.send('`{}` **blacklisted**'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.BoundsError as e: - await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.TagBoundsError as e: - await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.NotFound as e: - await ctx.send('`{}` **not found**'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.FavoritesNotFound: - await ctx.send('**You have no favorite tags**') - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.Timeout: - await ctx.send('**Request timed out**') - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - - # @e621.error - # async def e621_error(self, ctx, error): - # if isinstance(error, exc.NSFW): - # await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention)) - # await u.add_reaction(ctx.message, '\N{NO ENTRY}') + await self._get_images(ctx, args, booru='e621') # Searches for and returns images from e926.net given tags when not blacklisted @cmds.command(aliases=['e9', '9'], brief='e926 | SFW', description='e926 | SFW\nTag-based search for e926.net\n\nYou can only search 5 tags and 6 images at once for now.\ne9 [tags...] ([# of images])') @cmds.cooldown(1, 5, cmds.BucketType.member) async def e926(self, ctx, *args): - try: - kwargs = u.get_kwargs(ctx, args, limit=3) - args, limit = kwargs['remaining'], kwargs['limit'] - - tags = self._get_favorites(ctx, args) - - await ctx.trigger_typing() - - posts, order = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit) - - for ident, post in posts.items(): - embed = d.Embed(title=post['artist'], url='https://e926.net/post/show/{}'.format(ident), - color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) - embed.set_image(url=post['file_url']) - embed.set_author(name=' '.join(tags) if tags else order, - url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) - embed.set_footer( - text=post['score'], icon_url=self._get_score(post['score'])) - - message = await ctx.send(embed=embed) - - self.bot.loop.create_task(self.queue_for_hearts(message=message, send=embed)) - - except exc.TagBlacklisted as e: - await ctx.send('`{}` **blacklisted**'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.BoundsError as e: - await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.TagBoundsError as e: - await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.NotFound as e: - await ctx.send('`{}` **not found**'.format(e)) - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.FavoritesNotFound: - await ctx.send('**You have no favorite tags**') - await u.add_reaction(ctx.message, '\N{CROSS MARK}') - except exc.Timeout: - await ctx.send('**Request timed out**') - await u.add_reaction(ctx.message, '\N{CROSS MARK}') + await self._get_images(ctx, args, booru='e926') # @cmds.group(aliases=['fave', 'fav', 'f']) # async def favorite(self, ctx):