Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion bot/cogs/snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ def get_results_message(results: dict) -> Tuple[str, str]:

return msg, error

@staticmethod
def get_status_emoji(results: dict) -> str:
"""Return an emoji corresponding to the status code or lack of output in result."""
if not results["stdout"].strip(): # No output
return ":warning:"
elif results["returncode"] == 0: # No error
return ":white_check_mark:"
else: # Exception
return ":x:"

async def format_output(self, output: str) -> Tuple[str, Optional[str]]:
"""
Format the output and return a tuple of the formatted output and a URL to the full output.
Expand Down Expand Up @@ -201,7 +211,8 @@ async def eval_command(self, ctx: Context, *, code: str = None) -> None:
else:
output, paste_link = await self.format_output(results["stdout"])

msg = f"{ctx.author.mention} {msg}.\n\n```py\n{output}\n```"
icon = self.get_status_emoji(results)
msg = f"{ctx.author.mention} {icon} {msg}.\n\n```py\n{output}\n```"
if paste_link:
msg = f"{msg}\nFull output: {paste_link}"

Expand Down