From 28985df9fd98ae2d22b9606f80f63a96040424cf Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 24 Oct 2019 10:45:14 +0800 Subject: Prepend emoji indicative of success of !eval --- bot/cogs/snekbox.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index 81185cf3e..7316f9583 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -115,6 +115,16 @@ class Snekbox(Cog): 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. @@ -204,7 +214,8 @@ class Snekbox(Cog): 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}" -- cgit v1.2.3