From 654383b1168af8b54be982001d1d874543fb8b14 Mon Sep 17 00:00:00 2001 From: matnad Date: Thu, 21 Feb 2019 10:31:22 +0100 Subject: [PATCH] disable cmd, improve logging --- cogs/poll_controls.py | 141 +++++++++++++++++++++--------------------- pollmaster.py | 7 ++- 2 files changed, 76 insertions(+), 72 deletions(-) diff --git a/cogs/poll_controls.py b/cogs/poll_controls.py index f15b38f..93e3e22 100644 --- a/cogs/poll_controls.py +++ b/cogs/poll_controls.py @@ -258,75 +258,78 @@ class PollControls: @commands.command(pass_context=True) async def cmd(self, ctx, *, cmd=None): '''The old, command style way paired with the wizard.''' - server = await ask_for_server(self.bot, ctx.message) - if not server: - return - pre = await get_server_pre(self.bot, server) - - # generate the argparser and handle invalid stuff - descr = 'Accept poll settings via commandstring. \n\n' \ - '**Wrap all arguments in quotes like this:** \n' \ - f'{pre}cmd -question \"What tea do you like?\" -o \"green, black, chai\"\n\n' \ - 'The Order of arguments doesn\'t matter. If an argument is missing, it will use the default value. ' \ - 'If an argument is invalid, the wizard will step in. ' \ - 'If the command string is invalid, you will get this error :)' - parser = argparse.ArgumentParser(description=descr, formatter_class=CustomFormatter, add_help=False) - parser.add_argument('-question', '-q') - parser.add_argument('-label', '-l', default=str(await generate_word(self.bot, server.id))) - parser.add_argument('-options', '-o') - parser.add_argument('-multiple_choice', '-mc', default='1') - parser.add_argument('-roles', '-r', default='all') - parser.add_argument('-weights', '-w', default='none') - parser.add_argument('-deadline', '-d', default='0') - parser.add_argument('-anonymous', '-a', action="store_true") - - helpstring = parser.format_help() - helpstring = helpstring.replace("pollmaster.py", f"{pre}cmd ") - - if cmd and cmd == 'help': - await self.say_embed(ctx, say_text=helpstring) - return - - try: - cmds = shlex.split(cmd) - except ValueError: - await self.say_error(ctx, error_text=helpstring) - return - - try: - args, unknown_args = parser.parse_known_args(cmds) - except SystemExit: - await self.say_error(ctx, error_text=helpstring) - return - except: - return - - if unknown_args: - error_text = f'**There was an error reading the command line options!**.\n' \ - f'Most likely this is because you didn\'t surround the arguments with double quotes like this: ' \ - f'`{pre}cmd -q "question of the poll" -o "yes, no, maybe"`' \ - f'\n\nHere are the arguments I could not understand:\n' - error_text += '`'+'\n'.join(unknown_args)+'`' - error_text += f'\n\nHere are the arguments which are ok:\n' - error_text += '`' + '\n'.join([f'{k}: {v}' for k, v in vars(args).items()]) + '`' - - await self.say_error(ctx, error_text=error_text, footer_text=f'type `{pre}cmd help` for details.') - return - - # pass arguments to the wizard - async def route(poll): - await poll.set_name(force=args.question) - await poll.set_short(force=args.label) - await poll.set_anonymous(force=f'{"yes" if args.anonymous else "no"}') - await poll.set_options_reaction(force=args.options) - await poll.set_multiple_choice(force=args.multiple_choice) - await poll.set_roles(force=args.roles) - await poll.set_weights(force=args.weights) - await poll.set_duration(force=args.deadline) - - poll = await self.wizard(ctx, route, server) - if poll: - await poll.post_embed(destination=poll.channel) + await self.say_embed(ctx, say_text='This command is temporarily disabled.') + # server = await ask_for_server(self.bot, ctx.message) + # if not server: + # return + # pre = await get_server_pre(self.bot, server) + # + # # generate the argparser and handle invalid stuff + # descr = 'Accept poll settings via commandstring. \n\n' \ + # '**Wrap all arguments in quotes like this:** \n' \ + # f'{pre}cmd -question \"What tea do you like?\" -o \"green, black, chai\"\n\n' \ + # 'The Order of arguments doesn\'t matter. If an argument is missing, it will use the default value. ' \ + # 'If an argument is invalid, the wizard will step in. ' \ + # 'If the command string is invalid, you will get this error :)' + # parser = argparse.ArgumentParser(description=descr, formatter_class=CustomFormatter, add_help=False) + # parser.add_argument('-question', '-q') + # parser.add_argument('-label', '-l', default=str(await generate_word(self.bot, server.id))) + # parser.add_argument('-options', '-o') + # parser.add_argument('-multiple_choice', '-mc', default='1') + # parser.add_argument('-roles', '-r', default='all') + # parser.add_argument('-weights', '-w', default='none') + # parser.add_argument('-deadline', '-d', default='0') + # parser.add_argument('-anonymous', '-a', action="store_true") + # + # helpstring = parser.format_help() + # helpstring = helpstring.replace("pollmaster.py", f"{pre}cmd ") + # + # if cmd and cmd == 'help': + # await self.say_embed(ctx, say_text=helpstring) + # return + # + # try: + # cmds = shlex.split(cmd) + # except ValueError: + # await self.say_error(ctx, error_text=helpstring) + # return + # except: + # return + # + # try: + # args, unknown_args = parser.parse_known_args(cmds) + # except SystemExit: + # await self.say_error(ctx, error_text=helpstring) + # return + # except: + # return + # + # if unknown_args: + # error_text = f'**There was an error reading the command line options!**.\n' \ + # f'Most likely this is because you didn\'t surround the arguments with double quotes like this: ' \ + # f'`{pre}cmd -q "question of the poll" -o "yes, no, maybe"`' \ + # f'\n\nHere are the arguments I could not understand:\n' + # error_text += '`'+'\n'.join(unknown_args)+'`' + # error_text += f'\n\nHere are the arguments which are ok:\n' + # error_text += '`' + '\n'.join([f'{k}: {v}' for k, v in vars(args).items()]) + '`' + # + # await self.say_error(ctx, error_text=error_text, footer_text=f'type `{pre}cmd help` for details.') + # return + # + # # pass arguments to the wizard + # async def route(poll): + # await poll.set_name(force=args.question) + # await poll.set_short(force=args.label) + # await poll.set_anonymous(force=f'{"yes" if args.anonymous else "no"}') + # await poll.set_options_reaction(force=args.options) + # await poll.set_multiple_choice(force=args.multiple_choice) + # await poll.set_roles(force=args.roles) + # await poll.set_weights(force=args.weights) + # await poll.set_duration(force=args.deadline) + # + # poll = await self.wizard(ctx, route, server) + # if poll: + # await poll.post_embed(destination=poll.channel) @commands.command(pass_context=True) diff --git a/pollmaster.py b/pollmaster.py index 6e9182a..8a02aba 100644 --- a/pollmaster.py +++ b/pollmaster.py @@ -104,14 +104,15 @@ async def on_command_error(e, ctx): logger.error(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}') if SETTINGS.mode == 'development': raise e + traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) if SETTINGS.msg_errors: # send discord message for unexpected errors e = discord.Embed( title=f"Error With command: {ctx.command.name}", - description=f"```py\n{type(e).__name__}: {e}\n```\n\nContent:{ctx.message.content}" - f"\n\tServer: {ctx.message.server}\n\tChannel: <#{ctx.message.channel.id}>" - f"\n\tAuthor: <@{ctx.message.author.id}>", + description=f"```py\n{type(e).__name__}: {str(e)}\n```\n\nContent:{ctx.message.content}" + f"\n\tServer: {ctx.message.server}\n\tChannel: <#{ctx.message.channel}>" + f"\n\tAuthor: <@{ctx.message.author}>", timestamp=ctx.message.timestamp ) await bot.send_message(bot.owner, embed=e)