From e124ae3c11a69de0221f9435181d98348e4b8344 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Wed, 19 May 2021 16:36:18 +0200 Subject: [PATCH] Use ctx.send_interactive for SyntaxErrors in Dev cog * Merge pull request #5041 * Use ctx.send_interactive for SyntaxErrors in Dev cog * Paren in wrong place... --- redbot/core/dev_commands.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/redbot/core/dev_commands.py b/redbot/core/dev_commands.py index 8c9931d86..47a478c30 100644 --- a/redbot/core/dev_commands.py +++ b/redbot/core/dev_commands.py @@ -15,7 +15,7 @@ import discord from . import checks, commands from .commands import NoParseOptional as Optional from .i18n import Translator, cog_i18n -from .utils.chat_formatting import box, pagify +from .utils.chat_formatting import pagify from .utils.predicates import MessagePredicate """ @@ -71,16 +71,16 @@ class Dev(commands.Cog): # remove `foo` return content.strip("` \n") - @staticmethod - def get_syntax_error(e): + @classmethod + def get_syntax_error(cls, e): """Format a syntax error to send to the user. Returns a string representation of the error formatted as a codeblock. """ if e.text is None: - return box("{0.__class__.__name__}: {0}".format(e), lang="py") - return box( - "{0.text}\n{1:>{0.offset}}\n{2}: {0}".format(e, "^", type(e).__name__), lang="py" + return cls.get_pages("{0.__class__.__name__}: {0}".format(e)) + return cls.get_pages( + "{0.text}\n{1:>{0.offset}}\n{2}: {0}".format(e, "^", type(e).__name__) ) @staticmethod @@ -147,10 +147,12 @@ class Dev(commands.Cog): compiled = self.async_compile(code, "", "eval") result = await self.maybe_await(eval(compiled, env)) except SyntaxError as e: - await ctx.send(self.get_syntax_error(e)) + await ctx.send_interactive(self.get_syntax_error(e), box_lang="py") return except Exception as e: - await ctx.send(box("{}: {!s}".format(type(e).__name__, e), lang="py")) + await ctx.send_interactive( + self.get_pages("{}: {!s}".format(type(e).__name__, e)), box_lang="py" + ) return self._last_result = result @@ -190,7 +192,7 @@ class Dev(commands.Cog): compiled = self.async_compile(to_compile, "", "exec") exec(compiled, env) except SyntaxError as e: - return await ctx.send(self.get_syntax_error(e)) + return await ctx.send_interactive(self.get_syntax_error(e), box_lang="py") func = env["func"] result = None @@ -271,7 +273,7 @@ class Dev(commands.Cog): try: code = self.async_compile(cleaned, "", "exec") except SyntaxError as e: - await ctx.send(self.get_syntax_error(e)) + await ctx.send_interactive(self.get_syntax_error(e), box_lang="py") continue env["message"] = response