From 6d790fdbfea2909233b2ecfa79f579ef338d9f8e Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 8 Nov 2017 22:32:06 -0500 Subject: [PATCH 1/7] Added temp silencing of discord NotFound errors --- src/main/run.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/run.py b/src/main/run.py index fcbe5ae..ecfc2b8 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -9,6 +9,7 @@ from contextlib import suppress from pprint import pprint import discord as d +from discord import errors as err from discord import utils from discord.ext import commands from discord.ext.commands import errors as errext @@ -86,8 +87,10 @@ 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) + if isinstance(error, err.NotFound): + pass + elif isinstance(error, errext.CheckFailure): + await ctx.send('**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 bd487443219a3e9cc8f50fd4b99228157223b53a Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 8 Nov 2017 22:32:28 -0500 Subject: [PATCH 2/7] Added traceback to dm'd error logs --- src/main/run.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/run.py b/src/main/run.py index ecfc2b8..cf12975 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -73,7 +73,7 @@ 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}\n```\n{}```'.format(error)) + await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(''.join(tb.format_exception(type(error), error, error.__traceback__)))) 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['startup_chan']) @@ -99,8 +99,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} `{}` from *@{}* in {}\n```\n{}```'.format(ctx.message.content, ctx.author.name, ctx.guild.name, 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.guild.name, error)) + 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, ''.join(tb.format_exception(type(error), error, error.__traceback__)))) + await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.mention, ctx.channel.mention, 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 918a2229db3f14de07c1fc6aeebd90d3e89d5bfd Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 8 Nov 2017 22:32:48 -0500 Subject: [PATCH 3/7] Added WIP NSFW exception --- src/main/misc/exceptions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/misc/exceptions.py b/src/main/misc/exceptions.py index f90480a..7f9665c 100644 --- a/src/main/misc/exceptions.py +++ b/src/main/misc/exceptions.py @@ -5,6 +5,10 @@ async def send_error(ctx, error): await ctx.send('{}\n```\n{}```'.format(base, error)) +# class NSFW(errext.CheckFailure): +# pass + + class Wrong(Exception): pass From 9ed2c0a0cefff428453fd11dfce8caeade27b52b Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 8 Nov 2017 22:33:27 -0500 Subject: [PATCH 4/7] Converted appropriate exceptions to inherit CommandError --- src/main/misc/exceptions.py | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/main/misc/exceptions.py b/src/main/misc/exceptions.py index 7f9665c..dcc8c84 100644 --- a/src/main/misc/exceptions.py +++ b/src/main/misc/exceptions.py @@ -1,3 +1,5 @@ +from discord.ext.commands import errors as errext + base = '\N{WARNING SIGN} **An internal error has occurred.** This has been reported to my master. \N{WOLF FACE}' @@ -41,79 +43,79 @@ class GoTo(Exception): pass -class Exists(Exception): +class Exists(errext.CommandError): pass -class MissingArgument(Exception): +class MissingArgument(errext.CommandError): pass -class FavoritesNotFound(Exception): +class FavoritesNotFound(errext.CommandError): pass -class PostError(Exception): +class PostError(errext.CommandError): pass -class ImageError(Exception): +class ImageError(errext.CommandError): pass -class MatchError(Exception): +class MatchError(errext.CommandError): pass -class TagBlacklisted(Exception): +class TagBlacklisted(errext.CommandError): pass -class BoundsError(Exception): +class BoundsError(errext.CommandError): pass -class TagBoundsError(Exception): +class TagBoundsError(errext.CommandError): pass -class TagExists(Exception): +class TagExists(errext.CommandError): pass -class TagError(Exception): +class TagError(errext.CommandError): pass -class FlagError(Exception): +class FlagError(errext.CommandError): pass -class BlacklistError(Exception): +class BlacklistError(errext.CommandError): pass -class NotFound(Exception): +class NotFound(errext.CommandError): pass -class Timeout(Exception): +class Timeout(errext.CommandError): pass -class InvalidVideoFile(Exception): +class InvalidVideoFile(errext.CommandError): pass -class MissingAttachment(Exception): +class MissingAttachment(errext.CommandError): pass -class TooManyAttachments(Exception): +class TooManyAttachments(errext.CommandError): pass -class CheckFail(Exception): +class CheckFail(errext.CommandError): pass From 2b176a2853f88679d6dba2df9eba8e525d170edc Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 8 Nov 2017 22:36:06 -0500 Subject: [PATCH 5/7] Added ability for members with manage_messages to end paginators --- src/main/cogs/booru.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 32f96fc..52e537b 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -637,7 +637,7 @@ 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: + 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 @@ -775,7 +775,7 @@ class MsG: @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: + 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 @@ -939,7 +939,7 @@ class MsG: @checks.del_ctx() 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: + 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 From 16ff15b65d2d9d0ed46ab47e69bb61d34214995d Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 8 Nov 2017 22:37:04 -0500 Subject: [PATCH 6/7] Fixed returned order interfering with sequential posts fetches --- src/main/cogs/booru.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 52e537b..6bcb813 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -866,7 +866,8 @@ class MsG: try: if c % limit == 0: await dest.trigger_typing() - posts.update(await self._get_posts(ctx, booru='e621', tags=tags, limit=limit, previous=posts)) + temposts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit, previous=posts) + posts.update(temposts) keys = list(posts.keys()) values = list(posts.values()) @@ -1030,7 +1031,8 @@ class MsG: try: if c % limit == 0: await dest.trigger_typing() - posts.update(await self._get_posts(ctx, booru='e926', tags=tags, limit=limit, previous=posts)) + 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()) From a553efb0b6f2422bf2a1f620c9990522416603e8 Mon Sep 17 00:00:00 2001 From: Myned Date: Wed, 8 Nov 2017 22:37:45 -0500 Subject: [PATCH 7/7] WIP fix for double error with NSFW checkfail --- src/main/cogs/booru.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 6bcb813..7040299 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -930,11 +930,11 @@ class MsG: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - @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) - return await ctx.message.add_reaction('\N{NO ENTRY}') + # @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), delete_after=10) + # await ctx.message.add_reaction('\N{NO ENTRY}') @commands.command(name='e926page', aliases=['e926p', 'e9p', '9p']) @checks.del_ctx() @@ -1144,11 +1144,11 @@ class MsG: # tools.command_dict.setdefault(str(ctx.author.id), {}).update( # {'command': ctx.command, 'args': ctx.args}) - @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) - return await ctx.message.add_reaction('\N{NO ENTRY}') + # @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), delete_after=10) + # await ctx.message.add_reaction('\N{NO ENTRY}') # 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])')