1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-25 14:47:29 +00:00

Moved del_ctx to on_command_completion and removed decorators

This commit is contained in:
Myned 2017-11-20 06:03:26 -05:00
parent 8c83abca80
commit b1abb69303
6 changed files with 6 additions and 39 deletions

View file

@ -139,7 +139,6 @@ class MsG:
# Tag search # 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]') @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): async def _tags_related(self, ctx, *args):
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
dest, tags = kwargs['destination'], kwargs['remaining'] dest, tags = kwargs['destination'], kwargs['remaining']
@ -170,7 +169,6 @@ class MsG:
# Tag aliases # 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]') @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): async def _tags_aliases(self, ctx, *args):
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
dest, tags = kwargs['destination'], kwargs['remaining'] dest, tags = kwargs['destination'], kwargs['remaining']
@ -206,7 +204,6 @@ class MsG:
await ctx.message.add_reaction('\N{CROSS MARK}') 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]') @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): async def _get_info(self, ctx, *args):
try: try:
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
@ -241,7 +238,6 @@ class MsG:
await ctx.message.add_reaction('\N{CROSS MARK}') 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]') @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): async def _get_image(self, ctx, *args):
try: try:
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
@ -273,7 +269,6 @@ class MsG:
await ctx.message.add_reaction('\N{CROSS MARK}') 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]') @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): async def _get_pool(self, ctx, *args):
def on_reaction(reaction, user): 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:
@ -319,7 +314,6 @@ class MsG:
# Reverse image searches a linked image using the public iqdb # 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') @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): async def reverse(self, ctx, *args):
try: try:
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
@ -364,7 +358,6 @@ class MsG:
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@commands.command(name='reversify', aliases=['revify', 'risify', 'rify']) @commands.command(name='reversify', aliases=['revify', 'risify', 'rify'])
@checks.del_ctx()
async def reversify(self, ctx, *args): async def reversify(self, ctx, *args):
try: try:
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5) kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5)
@ -649,7 +642,6 @@ class MsG:
# Creates reaction-based paginator for linked pools # 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') @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): async def pool_paginator(self, ctx, *args):
def on_reaction(reaction, user): 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): 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) await ctx.author.send('`{} / {}`'.format(hearted.index(embed) + 1, len(hearted)), embed=embed)
@commands.command(name='e621page', aliases=['e621p', 'e6p', '6p']) @commands.command(name='e621page', aliases=['e621p', 'e6p', '6p'])
@checks.del_ctx()
@checks.is_nsfw() @checks.is_nsfw()
async def e621_paginator(self, ctx, *args): async def e621_paginator(self, ctx, *args):
def on_reaction(reaction, user): def on_reaction(reaction, user):
@ -942,7 +933,6 @@ class MsG:
# await ctx.message.add_reaction('\N{NO ENTRY}') # await ctx.message.add_reaction('\N{NO ENTRY}')
@commands.command(name='e926page', aliases=['e926p', 'e9p', '9p']) @commands.command(name='e926page', aliases=['e926p', 'e9p', '9p'])
@checks.del_ctx()
async def e926_paginator(self, ctx, *args): async def e926_paginator(self, ctx, *args):
def on_reaction(reaction, user): 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): 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 # 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])') @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() @checks.is_nsfw()
async def e621(self, ctx, *args): async def e621(self, ctx, *args):
try: try:
@ -1147,7 +1136,6 @@ class MsG:
# Searches for and returns images from e926.net given tags when not blacklisted # 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])') @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): async def e926(self, ctx, *args):
try: try:
kwargs = u.get_kwargs(ctx, args, limit=3) kwargs = u.get_kwargs(ctx, args, limit=3)
@ -1189,7 +1177,6 @@ class MsG:
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@commands.group(aliases=['fave', 'fav', 'f']) @commands.group(aliases=['fave', 'fav', 'f'])
@checks.del_ctx()
async def favorite(self, ctx): async def favorite(self, ctx):
if not ctx.invoked_subcommand: 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) 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 # 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])') @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): async def blacklist(self, ctx):
if not ctx.invoked_subcommand: 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) await ctx.send('**Use a flag to manage blacklists.**\n*Type* `{}help bl` *for more info.*'.format(ctx.prefix), delete_after=7)

View file

@ -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.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() @commands.is_owner()
@checks.del_ctx()
async def prune_all_user(self, ctx, user, when=None, reference=None): async def prune_all_user(self, ctx, user, when=None, reference=None):
def yes(msg): def yes(msg):
if msg.content.lower() == 'y' and msg.channel is ctx.channel and msg.author is ctx.author: 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.command(name='autodelete', aliases=['autodel'])
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
@checks.del_ctx()
async def auto_delete(self, ctx): async def auto_delete(self, ctx):
try: try:
if ctx.channel.id not in u.tasks['auto_del']: if ctx.channel.id not in u.tasks['auto_del']:

View file

@ -24,7 +24,6 @@ class Bot:
# Close connection to Discord - immediate offline # 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.command(name=',die', aliases=[',d'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def die(self, ctx): async def die(self, ctx):
await ctx.message.add_reaction('\N{CRESCENT MOON}') await ctx.message.add_reaction('\N{CRESCENT MOON}')
@ -44,7 +43,6 @@ class Bot:
@commands.command(name=',restart', aliases=[',res', ',r'], hidden=True) @commands.command(name=',restart', aliases=[',res', ',r'], hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def restart(self, ctx): async def restart(self, ctx):
await ctx.message.add_reaction('\N{SLEEPING SYMBOL}') await ctx.message.add_reaction('\N{SLEEPING SYMBOL}')
@ -66,7 +64,6 @@ class Bot:
# Invite bot to bot owner's server # 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.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() @commands.is_owner()
@checks.del_ctx()
async def invite(self, ctx): async def invite(self, ctx):
await ctx.message.add_reaction('\N{ENVELOPE}') await ctx.message.add_reaction('\N{ENVELOPE}')
@ -74,7 +71,6 @@ class Bot:
@commands.command(name=',status', aliases=[',presence', ',game'], hidden=True) @commands.command(name=',status', aliases=[',presence', ',game'], hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def status(self, ctx, *, game=None): async def status(self, ctx, *, game=None):
if game is not None: if game is not None:
await self.bot.change_presence(game=d.Game(name=game)) 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.command(name=',console', aliases=[',con', ',c'], hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def console(self, ctx): async def console(self, ctx):
def execute(msg): def execute(msg):
if msg.content.lower().startswith('exec ') and msg.author is ctx.author and msg.channel is ctx.channel: 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.command(name=',execute', aliases=[',exec'], hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def execute(self, ctx, *, exe): async def execute(self, ctx, *, exe):
try: try:
with io.StringIO() as buff, redirect_stdout(buff): with io.StringIO() as buff, redirect_stdout(buff):
@ -201,7 +195,6 @@ class Tools:
@commands.command(name=',evaluate', aliases=[',eval'], hidden=True) @commands.command(name=',evaluate', aliases=[',eval'], hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def evaluate(self, ctx, *, evl): async def evaluate(self, ctx, *, evl):
try: try:
with io.StringIO() as buff, redirect_stdout(buff): with io.StringIO() as buff, redirect_stdout(buff):
@ -213,7 +206,6 @@ class Tools:
@commands.group(aliases=[',db'], hidden=True) @commands.group(aliases=[',db'], hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def debug(self, ctx): async def debug(self, ctx):
console = await self.generate(ctx) console = await self.generate(ctx)

View file

@ -47,19 +47,16 @@ class Utils:
# Displays latency # Displays latency
@commands.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user') @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): async def ping(self, ctx):
await ctx.message.add_reaction('\N{TABLE TENNIS PADDLE AND BALL}') 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) 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') @commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
@checks.del_ctx()
async def prefix(self, 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']))) 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.group(name=',send', aliases=[',s'], hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def send(self, ctx): async def send(self, ctx):
pass pass

View file

@ -49,13 +49,3 @@ def is_nsfw():
return ctx.message.channel.is_nsfw() return ctx.message.channel.is_nsfw()
return True return True
return commands.check(predicate) 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)

View file

@ -134,7 +134,12 @@ async def on_command_error(ctx, error):
@bot.event @bot.event
async def on_command_completion(ctx): 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': if ctx.command.name != 'lastcommand':
u.last_commands[ctx.author.id] = ctx 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}) # suggested = u.setdefault('cogs/suggested.pkl', {'last_update': 'None', 'tags': {}, 'total': 0})
@bot.command(name=',test', hidden=True) @bot.command(name=',test', hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx()
async def test(ctx): async def test(ctx):
post = await u.fetch('https://e621.net/post/show.json?id=1145042', json=True) post = await u.fetch('https://e621.net/post/show.json?id=1145042', json=True)