mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
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...
This commit is contained in:
parent
3ff2132570
commit
e124ae3c11
@ -15,7 +15,7 @@ import discord
|
|||||||
from . import checks, commands
|
from . import checks, commands
|
||||||
from .commands import NoParseOptional as Optional
|
from .commands import NoParseOptional as Optional
|
||||||
from .i18n import Translator, cog_i18n
|
from .i18n import Translator, cog_i18n
|
||||||
from .utils.chat_formatting import box, pagify
|
from .utils.chat_formatting import pagify
|
||||||
from .utils.predicates import MessagePredicate
|
from .utils.predicates import MessagePredicate
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -71,16 +71,16 @@ class Dev(commands.Cog):
|
|||||||
# remove `foo`
|
# remove `foo`
|
||||||
return content.strip("` \n")
|
return content.strip("` \n")
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def get_syntax_error(e):
|
def get_syntax_error(cls, e):
|
||||||
"""Format a syntax error to send to the user.
|
"""Format a syntax error to send to the user.
|
||||||
|
|
||||||
Returns a string representation of the error formatted as a codeblock.
|
Returns a string representation of the error formatted as a codeblock.
|
||||||
"""
|
"""
|
||||||
if e.text is None:
|
if e.text is None:
|
||||||
return box("{0.__class__.__name__}: {0}".format(e), lang="py")
|
return cls.get_pages("{0.__class__.__name__}: {0}".format(e))
|
||||||
return box(
|
return cls.get_pages(
|
||||||
"{0.text}\n{1:>{0.offset}}\n{2}: {0}".format(e, "^", type(e).__name__), lang="py"
|
"{0.text}\n{1:>{0.offset}}\n{2}: {0}".format(e, "^", type(e).__name__)
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -147,10 +147,12 @@ class Dev(commands.Cog):
|
|||||||
compiled = self.async_compile(code, "<string>", "eval")
|
compiled = self.async_compile(code, "<string>", "eval")
|
||||||
result = await self.maybe_await(eval(compiled, env))
|
result = await self.maybe_await(eval(compiled, env))
|
||||||
except SyntaxError as e:
|
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
|
return
|
||||||
except Exception as e:
|
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
|
return
|
||||||
|
|
||||||
self._last_result = result
|
self._last_result = result
|
||||||
@ -190,7 +192,7 @@ class Dev(commands.Cog):
|
|||||||
compiled = self.async_compile(to_compile, "<string>", "exec")
|
compiled = self.async_compile(to_compile, "<string>", "exec")
|
||||||
exec(compiled, env)
|
exec(compiled, env)
|
||||||
except SyntaxError as e:
|
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"]
|
func = env["func"]
|
||||||
result = None
|
result = None
|
||||||
@ -271,7 +273,7 @@ class Dev(commands.Cog):
|
|||||||
try:
|
try:
|
||||||
code = self.async_compile(cleaned, "<repl session>", "exec")
|
code = self.async_compile(cleaned, "<repl session>", "exec")
|
||||||
except SyntaxError as e:
|
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
|
continue
|
||||||
|
|
||||||
env["message"] = response
|
env["message"] = response
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user