diff --git a/nomen/main.py b/nomen/main.py index c3f5b2e..ed8e449 100644 --- a/nomen/main.py +++ b/nomen/main.py @@ -9,7 +9,7 @@ from contextlib import redirect_stdout from disnake import Guild, Intents, Message from disnake.ext import commands -from disnake.ext.commands import Bot +from disnake.ext.commands import Bot, Paginator from dotenv import find_dotenv, load_dotenv from .db import run_db_migrations, setup_db @@ -142,13 +142,19 @@ async def on_command_error(ctx, error): log.error(error, exc_info=error) timestamp = int(ctx.message.created_at.timestamp()) + paginator = Paginator() + ptraceback = "".join(traceback.format_exception(error)) + for line in ptraceback.split("\n"): + paginator.add_line(line) await ctx.bot.owner.send( - f"# Command Error Occurred: {error}\n\n" - f"```\n{"".join(traceback.format_exception(error))}```\n\n" + f"# Command Error Occurred: {error}\n" f"## Context\n" f"**From:** {ctx.author.mention} ({ctx.author.name})\n" f", | [Jump to Command]({ctx.message.jump_url}) | <#{ctx.channel.id}>\n" + f"## Traceback" ) + for page in paginator.pages: + await ctx.bot.owner.send(page) await ctx.send( f"Error: {error}\n\n**Note:** Infinidoge (Developer) has already been sent a notification that an error occurred and will come investigate when available." ) @@ -156,18 +162,23 @@ async def on_command_error(ctx, error): @bot.event async def on_error(event, *args, **kwargs): - ptraceback = "".join(traceback.format_exc()) pargs = pprint.pformat(args) pkwargs = pprint.pformat(kwargs) + try: + paginator = Paginator() + for line in traceback.format_exc().split("\n"): + paginator.add_line(line) await bot.owner.send( - f"# Error Occurred: Event `{event}`" - f"```\n{ptraceback}```" - f"## args" - f"```\n{pargs}\n```" - f"## kwargs" - f"```\n{pkwargs}\n```" + f"# Error Occurred: Event `{event[:100]}`\n" + f"## args\n" + f"```\n{pargs}\n```\n" + f"## kwargs\n" + f"```\n{pkwargs}\n```\n" + f"## Traceback" ) + for page in paginator.pages: + await bot.owner.send(page) except: # Don't want recursive errors pass @@ -226,7 +237,11 @@ async def admin_eval(ctx, *, body: str): ret = await func() except Exception: value = stdout.getvalue() - await ctx.send("```py\n{}{}\n```".format(value, traceback.format_exc())) + ret = traceback.format_exc() + try: + await ctx.message.add_reaction("\u2705") + except: + pass else: value = stdout.getvalue() try: @@ -234,11 +249,18 @@ async def admin_eval(ctx, *, body: str): except: pass - if ret is None: - if value: - await ctx.send("```py\n{}\n```".format(value)) - else: - await ctx.send("```py\n{}{}\n```".format(value, ret)) + paginator = Paginator(prefix="```py", suffix="```") + if value: + for line in str(value).split("\n"): + paginator.add_line(line) + paginator.close_page() + if ret: + for line in str(ret).split("\n"): + paginator.add_line(line) + paginator.close_page() + + for page in paginator.pages: + await ctx.send(page) @bot.command()