From b1abb6930360a1bd6f1c4110f63477400fc0a64b Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 20 Nov 2017 06:03:26 -0500 Subject: [PATCH] Moved del_ctx to on_command_completion and removed decorators --- src/main/cogs/booru.py | 14 -------------- src/main/cogs/management.py | 2 -- src/main/cogs/owner.py | 8 -------- src/main/cogs/tools.py | 3 --- src/main/misc/checks.py | 10 ---------- src/main/run.py | 8 ++++++-- 6 files changed, 6 insertions(+), 39 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 4442497..c6907ef 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -139,7 +139,6 @@ class MsG: # Tag search @tags.command(name='related', aliases=['relate', 'rel'], brief='e621 - Search for related tags', description='Return related tags for given tag(s)', usage='[related|relate|rel]') - @checks.del_ctx() async def _tags_related(self, ctx, *args): kwargs = u.get_kwargs(ctx, args) dest, tags = kwargs['destination'], kwargs['remaining'] @@ -170,7 +169,6 @@ class MsG: # Tag aliases @tags.command(name='aliases', aliases=['alias', 'als'], brief='e621 - Search for tag aliases', description='Return aliases for given tag(s)', usage='[aliases|alias|als]') - @checks.del_ctx() async def _tags_aliases(self, ctx, *args): kwargs = u.get_kwargs(ctx, args) dest, tags = kwargs['destination'], kwargs['remaining'] @@ -206,7 +204,6 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') @get.command(name='info', aliases=['i'], brief='e621 - Get info from post', description='Return info for given post', usage='[info|i]') - @checks.del_ctx() async def _get_info(self, ctx, *args): try: kwargs = u.get_kwargs(ctx, args) @@ -241,7 +238,6 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') @get.command(name='image', aliases=['img'], brief='e621 - Get image link', description='Return image for given post', usage='[image|img]') - @checks.del_ctx() async def _get_image(self, ctx, *args): try: kwargs = u.get_kwargs(ctx, args) @@ -273,7 +269,6 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') @get.command(name='pool', aliases=['p'], brief='e621 - Get pool link', description='Return pool info for given query', usage='[pool|p]') - @checks.del_ctx() async def _get_pool(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: @@ -319,7 +314,6 @@ class MsG: # Reverse image searches a linked image using the public iqdb @commands.command(name='reverse', aliases=['rev', 'ris'], brief='e621 Reverse image search', description='e621 | NSFW\nReverse-search an image with given URL') - @checks.del_ctx() async def reverse(self, ctx, *args): try: kwargs = u.get_kwargs(ctx, args) @@ -364,7 +358,6 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') @commands.command(name='reversify', aliases=['revify', 'risify', 'rify']) - @checks.del_ctx() async def reversify(self, ctx, *args): try: kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5) @@ -649,7 +642,6 @@ class MsG: # Creates reaction-based paginator for linked pools @commands.command(name='poolpage', aliases=['poolp', 'pp', 'e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format') - @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.permissions_in(reaction.message.channel).manage_messages): @@ -781,7 +773,6 @@ class MsG: await ctx.author.send('`{} / {}`'.format(hearted.index(embed) + 1, len(hearted)), embed=embed) @commands.command(name='e621page', aliases=['e621p', 'e6p', '6p']) - @checks.del_ctx() @checks.is_nsfw() async def e621_paginator(self, ctx, *args): def on_reaction(reaction, user): @@ -942,7 +933,6 @@ class MsG: # await ctx.message.add_reaction('\N{NO ENTRY}') @commands.command(name='e926page', aliases=['e926p', 'e9p', '9p']) - @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 or user.permissions_in(reaction.message.channel).manage_messages): @@ -1097,7 +1087,6 @@ class MsG: # Searches for and returns images from e621.net given tags when not blacklisted @commands.group(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.del_ctx() @checks.is_nsfw() async def e621(self, ctx, *args): try: @@ -1147,7 +1136,6 @@ class MsG: # 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])') - @checks.del_ctx() async def e926(self, ctx, *args): try: kwargs = u.get_kwargs(ctx, args, limit=3) @@ -1189,7 +1177,6 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') @commands.group(aliases=['fave', 'fav', 'f']) - @checks.del_ctx() async def favorite(self, ctx): if not ctx.invoked_subcommand: await ctx.send('**Use a flag to manage favorites.**\n*Type* `{}help fav` *for more info.*'.format(ctx.prefix), delete_after=7) @@ -1300,7 +1287,6 @@ class MsG: # Umbrella command structure to manage global, channel, and user blacklists @commands.group(aliases=['bl', 'b'], brief='Manage blacklists', description='Blacklist base command for managing blacklists\n\n`bl get [blacklist]` to show a blacklist\n`bl set [blacklist] [tags]` to replace a blacklist\n`bl clear [blacklist]` to clear a blacklist\n`bl add [blacklist] [tags]` to add tags to a blacklist\n`bl remove [blacklist] [tags]` to remove tags from a blacklist', usage='[flag] [blacklist] ([tags])') - @checks.del_ctx() async def blacklist(self, ctx): if not ctx.invoked_subcommand: await ctx.send('**Use a flag to manage blacklists.**\n*Type* `{}help bl` *for more info.*'.format(ctx.prefix), delete_after=7) diff --git a/src/main/cogs/management.py b/src/main/cogs/management.py index 56b3e7e..14cc876 100644 --- a/src/main/cogs/management.py +++ b/src/main/cogs/management.py @@ -30,7 +30,6 @@ class Administration: @commands.command(name=',prunefromguild', aliases=[',pfg', ',prunefromserver', ',pfs'], brief='Prune a user\'s messages from the guild', description='about flag centers on message 50 of 101 messages\n\npfg \{user id\} [before|after|about] [\{message id\}]\n\nExample:\npfg \{user id\} before \{message id\}') @commands.is_owner() - @checks.del_ctx() async def prune_all_user(self, ctx, user, when=None, reference=None): def yes(msg): if msg.content.lower() == 'y' and msg.channel is ctx.channel and msg.author is ctx.author: @@ -147,7 +146,6 @@ class Administration: @commands.command(name='autodelete', aliases=['autodel']) @commands.has_permissions(administrator=True) - @checks.del_ctx() async def auto_delete(self, ctx): try: if ctx.channel.id not in u.tasks['auto_del']: diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index d235bef..a3381fa 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -24,7 +24,6 @@ class Bot: # Close connection to Discord - immediate offline @commands.command(name=',die', aliases=[',d'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True) @commands.is_owner() - @checks.del_ctx() async def die(self, ctx): await ctx.message.add_reaction('\N{CRESCENT MOON}') @@ -44,7 +43,6 @@ class Bot: @commands.command(name=',restart', aliases=[',res', ',r'], hidden=True) @commands.is_owner() - @checks.del_ctx() async def restart(self, ctx): await ctx.message.add_reaction('\N{SLEEPING SYMBOL}') @@ -66,7 +64,6 @@ class Bot: # Invite bot to bot owner's server @commands.command(name=',invite', aliases=[',inv', ',link'], brief='Invite the bot', description='BOT OWNER ONLY\nInvite the bot to a server (Requires admin)', hidden=True) @commands.is_owner() - @checks.del_ctx() async def invite(self, ctx): await ctx.message.add_reaction('\N{ENVELOPE}') @@ -74,7 +71,6 @@ class Bot: @commands.command(name=',status', aliases=[',presence', ',game'], hidden=True) @commands.is_owner() - @checks.del_ctx() async def status(self, ctx, *, game=None): if game is not None: await self.bot.change_presence(game=d.Game(name=game)) @@ -115,7 +111,6 @@ class Tools: @commands.command(name=',console', aliases=[',con', ',c'], hidden=True) @commands.is_owner() - @checks.del_ctx() async def console(self, ctx): def execute(msg): if msg.content.lower().startswith('exec ') and msg.author is ctx.author and msg.channel is ctx.channel: @@ -189,7 +184,6 @@ class Tools: @commands.command(name=',execute', aliases=[',exec'], hidden=True) @commands.is_owner() - @checks.del_ctx() async def execute(self, ctx, *, exe): try: with io.StringIO() as buff, redirect_stdout(buff): @@ -201,7 +195,6 @@ class Tools: @commands.command(name=',evaluate', aliases=[',eval'], hidden=True) @commands.is_owner() - @checks.del_ctx() async def evaluate(self, ctx, *, evl): try: with io.StringIO() as buff, redirect_stdout(buff): @@ -213,7 +206,6 @@ class Tools: @commands.group(aliases=[',db'], hidden=True) @commands.is_owner() - @checks.del_ctx() async def debug(self, ctx): console = await self.generate(ctx) diff --git a/src/main/cogs/tools.py b/src/main/cogs/tools.py index ba32246..588ebd4 100644 --- a/src/main/cogs/tools.py +++ b/src/main/cogs/tools.py @@ -47,19 +47,16 @@ class Utils: # Displays latency @commands.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user') - @checks.del_ctx() async def ping(self, ctx): await ctx.message.add_reaction('\N{TABLE TENNIS PADDLE AND BALL}') await ctx.send(ctx.author.mention + ' \N{TABLE TENNIS PADDLE AND BALL} `' + str(round(self.bot.latency * 1000)) + 'ms`', delete_after=5) @commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes') - @checks.del_ctx() async def prefix(self, ctx): await ctx.send('**Prefix:** `{}`'.format('` or `'.join(u.settings['prefixes'][ctx.guild.id] if ctx.guild.id in u.settings['prefixes'] else u.config['prefix']))) @commands.group(name=',send', aliases=[',s'], hidden=True) @commands.is_owner() - @checks.del_ctx() async def send(self, ctx): pass diff --git a/src/main/misc/checks.py b/src/main/misc/checks.py index 1c080e8..fda1f2b 100644 --- a/src/main/misc/checks.py +++ b/src/main/misc/checks.py @@ -49,13 +49,3 @@ def is_nsfw(): return ctx.message.channel.is_nsfw() return True return commands.check(predicate) - - -def del_ctx(): - async def predicate(ctx): - 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) diff --git a/src/main/run.py b/src/main/run.py index c6fa59c..16b1604 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -134,7 +134,12 @@ async def on_command_error(ctx, error): @bot.event async def on_command_completion(ctx): - await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + with suppress(err.NotFound): + 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): + await ctx.message.delete() + + await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') if ctx.command.name != 'lastcommand': u.last_commands[ctx.author.id] = ctx @@ -166,7 +171,6 @@ def after(voice, error): # suggested = u.setdefault('cogs/suggested.pkl', {'last_update': 'None', 'tags': {}, 'total': 0}) @bot.command(name=',test', hidden=True) @commands.is_owner() -@checks.del_ctx() async def test(ctx): post = await u.fetch('https://e621.net/post/show.json?id=1145042', json=True)