attempt to improve character stripping in eval command
@@ -52,8 +52,10 @@ class Owner(commands.Cog):
@commands.command(name="eval")
@commands.is_owner()
async def eval_stuff(self, ctx, *, code):
- try:
- code_nice = "async def eval_code():\n" + "\n".join(f" {i}" for i in code.strip(" `py\n ").splitlines())
+ if code.startswith("```"):
+ code = code.lstrip(" `py\n ").rstrip(" `\n ")
+
+ code_nice = "async def eval_code():\n" + "\n".join(f" {i}" for i in code.splitlines())
code_parsed = ast.parse(code_nice)
code_final = code_parsed.body[0].body
@@ -73,15 +75,15 @@ class Owner(commands.Cog):
env = {**locals(), **globals()}
+ try:
exec(compile(code_parsed, filename="<ast>", mode="exec"), env)
result = await eval("eval_code()", env)
-
- await ctx.send(f"```py\n{result}```")
-
except discord.errors.Forbidden:
await ctx.send("Missing permissions (FORBIDDEN)")
except Exception as e:
await self.bot.get_cog("Events").debug_error(ctx, e, ctx)
+ else:
+ await ctx.send(f"```py\n{result}```")
@commands.command(name="gitpull")
@commands.max_concurrency(1, per=commands.BucketType.default, wait=True)
