From b05561e254e90bdc23f0cc524e38c84ff8d21dd3 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 17 Oct 2017 01:49:52 -0400 Subject: [PATCH 1/3] Suppressed AttributeError for dms --- src/main/misc/checks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/misc/checks.py b/src/main/misc/checks.py index 47c1c6b..1c080e8 100644 --- a/src/main/misc/checks.py +++ b/src/main/misc/checks.py @@ -53,8 +53,9 @@ def is_nsfw(): def del_ctx(): async def predicate(ctx): - if ctx.guild.id in u.settings['del_ctx'] and ctx.me.permissions_in(ctx.channel).manage_messages and isinstance(ctx.message.channel, d.TextChannel): - with suppress(err.NotFound): - await ctx.message.delete() + with suppress(AttributeError): + if ctx.guild.id in u.settings['del_ctx'] and ctx.me.permissions_in(ctx.channel).manage_messages and isinstance(ctx.message.channel, d.TextChannel): + with suppress(err.NotFound): + await ctx.message.delete() return True return commands.check(predicate) From 16fc5d663d48eec140e025bc704fcce6bcb42583 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 17 Oct 2017 01:51:40 -0400 Subject: [PATCH 2/3] Added dm report for on_error --- src/main/run.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/run.py b/src/main/run.py index 6d4730f..f579027 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -54,7 +54,8 @@ async def on_ready(): 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_channel(u.config['info_channel']).send('**ERROR** ⚠️ {}'.format(error)) + await bot.get_user(u.config['owner_id']).send('**ERROR** ⚠️ `{}`'.format(error)) + await bot.get_channel(u.config['info_channel']).send('**ERROR** ⚠️ `{}`'.format(error)) # u.notify('E R R O R') await bot.logout() u.close(bot.loop) @@ -64,14 +65,15 @@ async def on_error(error, *args, **kwargs): async def on_command_error(ctx, error): if isinstance(error, errext.CheckFailure): await ctx.send('⛔️ **Insufficient permissions.**', delete_after=10) + await ctx.message.add_reaction('⛔️') elif isinstance(error, errext.CommandNotFound): print('INVALID COMMAND : {}'.format(error), file=sys.stderr) else: 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** ⚠️ {}'.format(error)) - await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** ⚠️ {}'.format(error)) + await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** ⚠️ `{}`'.format(error)) + await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** ⚠️ `{}`'.format(error)) await exc.send_error(ctx, error) # u.notify('C O M M A N D E R R O R') From 347b121522d846a1092a793d15657910d847cb31 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 17 Oct 2017 01:52:06 -0400 Subject: [PATCH 3/3] Fixed embed colors inhibiting dm command access --- src/main/cogs/booru.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 1d36417..d8c28ad 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -21,6 +21,7 @@ class MsG: def __init__(self, bot): self.bot = bot + self.color = d.Color(0x1A1A1A) self.LIMIT = 100 self.RATE_LIMIT = u.RATE_LIMIT self.queue = asyncio.Queue() @@ -498,7 +499,7 @@ class MsG: values = list(posts.values()) embed = d.Embed( - title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color).set_image(url=values[c - 1]['url']) + title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=values[c - 1]['url']) embed.set_author(name=pool['name'], url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=ctx.author.avatar_url) embed.set_footer(text='{} / {}'.format(c, len(posts)), @@ -618,9 +619,9 @@ class MsG: posts = {} c = 0 while len(posts) < limit: - if c == 50 + limit * 3: + if c == limit * 5 + self.LIMIT: raise exc.Timeout - request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': ','.join(['order:random'] + tags), 'limit': self.LIMIT}, json=True) + request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': ','.join(['order:random'] + tags), 'limit': self.LIMIT * limit}, json=True) if len(request) == 0: raise exc.NotFound(formatter.tostring(tags)) if len(request) < limit: @@ -681,7 +682,7 @@ class MsG: values = list(posts.values()) embed = d.Embed( - title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color).set_image(url=values[c - 1]['url']) + title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=values[c - 1]['url']) embed.set_author(name=formatter.tostring(args, random=True), url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.author.avatar_url) embed.set_footer(text='{} / {}'.format(c, len(posts)), @@ -797,7 +798,7 @@ class MsG: async def e621_paginator_error(self, ctx, error): if isinstance(error, errext.CheckFailure): await ctx.send('⛔️ {} **is not an NSFW channel.**'.format(ctx.channel.mention), delete_after=10) - return await ctx.message.add_reaction('❌') + return await ctx.message.add_reaction('⛔️') def get_limit(self, args): limit = 1 @@ -831,7 +832,7 @@ class MsG: for ident, post in posts.items(): embed = d.Embed(title=post['author'], url='https://e621.net/post/show/{}'.format(ident), - color=ctx.me.color).set_image(url=post['url']) + color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url']) embed.set_author(name=formatter.tostring(args, random=True), url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.author.avatar_url) embed.set_footer( @@ -866,7 +867,8 @@ class MsG: @e621.error async def e621_error(self, ctx, error): if isinstance(error, errext.CheckFailure): - return await ctx.send('⛔️ {} **is not an NSFW channel.**'.format(ctx.channel.mention), delete_after=10) + await ctx.send('⛔️ {} **is not an NSFW channel.**'.format(ctx.channel.mention), delete_after=10) + return await ctx.message.add_reaction('⛔️') # Searches for and returns images from e926.net given tags when not blacklisted @commands.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])') @@ -884,7 +886,7 @@ class MsG: for ident, post in posts.items(): embed = d.Embed(title=post['author'], url='https://e926.net/post/show/{}'.format(ident), - color=ctx.me.color).set_image(url=post['url']) + color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url']) embed.set_author(name=formatter.tostring(args, random=True), url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.author.avatar_url) embed.set_footer(