From a3d9ac81d9e516cdfdb98df9e5f405de2470d214 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 21 Dec 2017 22:38:59 -0500 Subject: [PATCH 1/4] WIP Help command rework --- src/cogs/booru.py | 22 +++++++++++----------- src/run.py | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 58495ca..59ce58f 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -176,7 +176,7 @@ class MsG: pass # Tag search - @tags.command(name='related', aliases=['relate', 'rel'], brief='(tags) Search for related tags', description='Return related tags for given tag(s)\n\nExample:\n\{p\}tag related wolf') + @tags.command(name='related', aliases=['relate', 'rel', 'r'], brief='(tags) Search for related tags', description='Return related tags for given tag(s)\n\nExample:\n\{p\}tag related wolf') async def _tags_related(self, ctx, *args): kwargs = u.get_kwargs(ctx, args) dest, tags = kwargs['destination'], kwargs['remaining'] @@ -206,7 +206,7 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') # Tag aliases - @tags.command(name='aliases', aliases=['alias', 'als'], brief='(tags) Search for tag aliases', description='Return aliases for given tag(s)\n\nExample:\n\{p\}tag alias wolf') + @tags.command(name='aliases', aliases=['alias', 'als', 'a'], brief='(tags) Search for tag aliases', description='Return aliases for given tag(s)\n\nExample:\n\{p\}tag alias wolf') async def _tags_aliases(self, ctx, *args): kwargs = u.get_kwargs(ctx, args) dest, tags = kwargs['destination'], kwargs['remaining'] @@ -1345,7 +1345,7 @@ class MsG: pass # Umbrella command structure to manage global, channel, and user blacklists - @cmds.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])') + @cmds.group(aliases=['bl', 'b'], brief='(G) Manage blacklists', description='Manage channel or personal blacklists\n\nUsage:\n\{p\}bl get \{blacklist\} to show a blacklist\n\{p\}bl clear \{blacklist\} to clear a blacklist\n\{p\}bl add \{blacklist\} \{tags...\} to add tag(s) to a blacklist\n\{p\}bl remove \{blacklist\} \{tags...\} to remove tags from a blacklist') 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) @@ -1356,19 +1356,19 @@ class MsG: # if isinstance(error, KeyError): # return await ctx.send('**Blacklist does not exist**', delete_after=7) - @blacklist.group(name='get', aliases=['g']) + @blacklist.group(name='get', aliases=['g'], brief='(G) Get a blacklist\n\nUsage:\n\{p\}bl get \{blacklist\}') async def _get_blacklist(self, ctx): if not ctx.invoked_subcommand: await ctx.send('**Invalid blacklist**', delete_after=7) await ctx.message.add_reaction('\N{CROSS MARK}') - @_get_blacklist.command(name='global', aliases=['gl', 'g']) + @_get_blacklist.command(name='global', aliases=['gl', 'g'], brief='Get current global blacklist', description='Get current global blacklist\n\nThis applies to all booru commands, in accordance with Discord\'s ToS agreement\n\nExample:\n\{p\}bl get global') async def __get_global_blacklist(self, ctx, *args): dest = u.get_kwargs(ctx, args)['destination'] await dest.send('\N{NO ENTRY SIGN} **Global blacklist:**\n```\n{}```'.format(formatter.tostring(self.blacklists['global_blacklist']))) - @_get_blacklist.command(name='channel', aliases=['ch', 'c']) + @_get_blacklist.command(name='channel', aliases=['ch', 'c'], brief='Get current channel blacklist', description='Get current channel blacklist\n\nThis is based on context - the channel where the command was executed\n\nExample:\{p\}bl get channel') async def __get_channel_blacklist(self, ctx, *args): dest = u.get_kwargs(ctx, args)['destination'] @@ -1377,13 +1377,13 @@ class MsG: await dest.send('\N{NO ENTRY SIGN} {} **blacklist:**\n```\n{}```'.format(ctx.channel.mention, formatter.tostring(self.blacklists['guild_blacklist'].get(guild.id, {}).get(ctx.channel.id, set())))) - @_get_blacklist.command(name='me', aliases=['m']) + @_get_blacklist.command(name='me', aliases=['m'], brief='Get your personal blacklist', description='Get your personal blacklist\n\nYour blacklist is not viewable by anyone but you, except if you call this command in a public channel. The blacklist will be deleted soon after for your privacy\n\nExample:\n\{p\}bl get me') async def __get_user_blacklist(self, ctx, *args): dest = u.get_kwargs(ctx, args)['destination'] await dest.send('\N{NO ENTRY SIGN} {}**\'s blacklist:**\n```\n{}```'.format(ctx.author.mention, formatter.tostring(self.blacklists['user_blacklist'].get(ctx.author.id, set()))), delete_after=7) - @_get_blacklist.command(name='here', aliases=['h']) + @_get_blacklist.command(name='here', aliases=['h'], brief='Get current global and channel blacklists', description='Get current global and channel blacklists in a single message\n\nExample:\{p\}bl get here') async def __get_here_blacklists(self, ctx, *args): dest = u.get_kwargs(ctx, args)['destination'] @@ -1392,7 +1392,7 @@ class MsG: await dest.send('\N{NO ENTRY SIGN} **__Blacklisted:__**\n\n**Global:**\n```\n{}```\n**{}:**\n```\n{}```'.format(formatter.tostring(self.blacklists['global_blacklist']), ctx.channel.mention, formatter.tostring(self.blacklists['guild_blacklist'].get(guild.id, {}).get(ctx.channel.id, set())))) - @_get_blacklist.group(name='all', aliases=['a']) + @_get_blacklist.group(name='all', aliases=['a'], hidden=True) async def __get_all_blacklists(self, ctx): if not ctx.invoked_subcommand: await ctx.send('**Invalid blacklist**') @@ -1415,7 +1415,7 @@ class MsG: await dest.send('\N{NO ENTRY SIGN} **__User blacklists:__**\n\n{}'.format(formatter.dict_tostring(self.blacklists['user_blacklist']))) - @blacklist.group(name='add', aliases=['a']) + @blacklist.group(name='add', aliases=['a'], brief='(G) Add tag(s) to a blacklist\n\nUsage:\n\{p\}bl add \{blacklist\} \{tags...\}') async def _add_tags(self, ctx): if not ctx.invoked_subcommand: await ctx.send('**Invalid blacklist**', delete_after=7) @@ -1442,7 +1442,7 @@ class MsG: await dest.send('**Added to global blacklist:**\n```\n{}```'.format(formatter.tostring(tags)), delete_after=5) - @_add_tags.command(name='channel', aliases=['ch', 'c']) + @_add_tags.command(name='channel', aliases=['ch', 'c'], brief='@manage_channel@ Add tag(s) to the current channel blacklist (requires manage_channel)', description='Add tag(s) to the current channel blacklist ') @cmds.has_permissions(manage_channels=True) async def __add_channel_tags(self, ctx, *args): kwargs = u.get_kwargs(ctx, args) diff --git a/src/run.py b/src/run.py index f50d6d8..5a2c2f8 100644 --- a/src/run.py +++ b/src/run.py @@ -58,7 +58,7 @@ def get_prefix(bot, message): return u.settings['prefixes'].get(message.guild.id, u.config['prefix']) return u.config['prefix'] -bot = cmds.Bot(command_prefix=get_prefix, self_bot=u.config['selfbot'], formatter=cmds.HelpFormatter(show_check_failure=True), description='Modufur - A booru bot with a side of management and automated tasking\nMade by @Myned#3985\n\nNSFW for Not Safe For Wumpus commands\n(G) for group commands\np for prefix\n\n\{\} for mandatory argument\n[] for optional argument', help_attrs={'aliases': ['h']}, pm_help=None) +bot = cmds.Bot(command_prefix=get_prefix, self_bot=u.config['selfbot'], formatter=cmds.HelpFormatter(show_check_failure=True), description='Modufur - A booru bot with a side of management and automated tasking\nMade by @Myned#3985\n\nNSFW for Not Safe For Wumpus commands\n(G) for group commands\n@permission@ for required permissions\n!notice! for important information\np for prefix\n\n\{\} for mandatory argument\n[] for optional argument\n... for one or more arguments', help_attrs={'aliases': ['h']}, pm_help=None) @bot.command(help='help', brief='brief', description='description', usage='usage', hidden=True) async def test(ctx): From 4d188e2a4a719869f00a2955263acef3dc609e13 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 21 Dec 2017 22:39:20 -0500 Subject: [PATCH 2/4] Added json to setdefault helper method --- src/utils/utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index 19a5948..5ca1346 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -36,7 +36,8 @@ except FileNotFoundError: 'FILE NOT FOUND : config.json created with abstract values. Restart run.py with correct values') -def setdefault(filename, default=None): +def setdefault(filename, default=None, json=False): + if not json: try: with open(filename, 'rb') as infile: print('LOADED : {}'.format(filename)) @@ -47,6 +48,17 @@ def setdefault(filename, default=None): pkl.dump(default, iofile) iofile.seek(0) return pkl.load(iofile) + else: + try: + with open(filename, 'rb') as infile: + print(f'LOADED : {filename}') + return jsn.load(infile) + except FileNotFoundError: + with open(filename, 'wb+') as iofile: + print(f'FILE NOT FOUND : {filename} created and loaded with default values') + jsn.dump(default, iofile) + iofile.seek(0) + return jsn.load(iofile) def load(filename, *, json=False): From 0f60985c788fc5d9693798ca3eaf358e6799acf9 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 21 Dec 2017 22:39:44 -0500 Subject: [PATCH 3/4] Removed on_ready testing --- src/run.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/run.py b/src/run.py index 5a2c2f8..ee8da28 100644 --- a/src/run.py +++ b/src/run.py @@ -115,8 +115,6 @@ async def on_message(message): @bot.event async def on_error(error, *args, **kwargs): - print(bot.is_closed()) - print(bot.is_ready()) 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)) From b8b0637c8ab837861d8fe52b07fe3937af9419d5 Mon Sep 17 00:00:00 2001 From: Myned Date: Thu, 21 Dec 2017 22:40:34 -0500 Subject: [PATCH 4/4] Fixed error message TypeError --- src/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run.py b/src/run.py index ee8da28..933a153 100644 --- a/src/run.py +++ b/src/run.py @@ -151,7 +151,7 @@ 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.mention, ctx.channel.mention, ''.join(tb.format_exception(type(error), error, error.__traceback__ if len(error.__traceback__) < 1500 else error.__traceback__[:1500])))) + 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__ if len(str(error.__traceback__)) < 1500 else str(error.__traceback__)[:1500])))) 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}')