Skip to content

Commit

Permalink
cleaned up eval.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nfearnley committed May 21, 2024
1 parent 4d35d9a commit ade6353
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sizebot/cogs/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, bot: commands.Bot):
@commands.is_owner()
async def eval(self, ctx: BotContext, *, evalStr: str):
"""Evaluate a Python expression."""
evalStr = remove_code_block(evalStr)
evalStr = _remove_code_block(evalStr)

logger.info(f"{ctx.author.display_name} tried to eval {evalStr!r}.")

Expand All @@ -39,7 +39,7 @@ async def eval(self, ctx: BotContext, *, evalStr: str):
result = await run_eval(ctx, evalStr)
except Exception as err:
logger.error("eval error:\n" + utils.format_traceback(err))
await ctx.send(emojis.warning + f" ` {format_error(err)} `")
await ctx.send(emojis.warning + f" ` {_format_error(err)} `")
return
finally:
# Remove wait message when done
Expand All @@ -63,7 +63,7 @@ async def evil(self, ctx: BotContext, *, evalStr: str):
# PERMISSION: requires manage_messages
await ctx.message.delete(delay = 0)

evalStr = remove_code_block(evalStr)
evalStr = _remove_code_block(evalStr)

logger.info(f"{ctx.author.display_name} tried to quietly eval {evalStr!r}.")

Expand All @@ -72,10 +72,10 @@ async def evil(self, ctx: BotContext, *, evalStr: str):
await run_eval(ctx, evalStr)
except Exception as err:
logger.error("eval error:\n" + utils.format_traceback(err))
await ctx.author.send(emojis.warning + f" ` {format_error(err)} `")
await ctx.author.send(emojis.warning + f" ` {_format_error(err)} `")


def remove_code_block(s: str) -> str:
def _remove_code_block(s: str) -> str:
re_codeblock = re.compile(r"^\s*```(?:python)?(.*)```\s*$", re.DOTALL)
s_nocodeblock = re.sub(re_codeblock, r"\1", s)
if s_nocodeblock != s:
Expand All @@ -89,7 +89,7 @@ def remove_code_block(s: str) -> str:
return s


def format_error(err: Exception) -> str:
def _format_error(err: Exception) -> str:
fullname = utils.get_fullname(err)

errMessage = str(err)
Expand Down

0 comments on commit ade6353

Please sign in to comment.