From e5fbddbe56921d46bf7f8451aef6c859214b2709 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Wed, 1 Mar 2023 16:45:24 +0530 Subject: Add warning message when using `input` --- bot/exts/utils/snekbox.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index 8a2e68b28..7ee5c5d21 100644 --- a/bot/exts/utils/snekbox.py +++ b/bot/exts/utils/snekbox.py @@ -344,8 +344,14 @@ class Snekbox(Cog): log.trace("Formatting output...") output, paste_link = await self.format_output(results["stdout"]) + warning_message = "" + # 33 is the length of the error message. It is done to make sure the last line of output contains + # the error and the error is not manually printed by the author with a syntax error. + if "EOFError: EOF when reading a line" in output[-33:] and results['returncode'] == 1: + warning_message += ":warning: Note: `input` is not supported by the bot :warning:\n\n" + icon = self.get_status_emoji(results) - msg = f"{ctx.author.mention} {icon} {msg}.\n\n```\n{output}\n```" + msg = f"{ctx.author.mention} {icon} {msg}.\n\n{warning_message}```\n{output}\n```" if paste_link: msg = f"{msg}\nFull output: {paste_link}" -- cgit v1.2.3 From f0119faacfd9db6f972a56d74e327a00a2e29a48 Mon Sep 17 00:00:00 2001 From: Mohammad Ibrahim <74553450+Ibrahim2750mi@users.noreply.github.com> Date: Fri, 3 Mar 2023 01:53:55 +0530 Subject: Wookie's review + Double quotes for consistency + Using results["stdout"] instead of output so the warning is still displayed if the error doesn't fit in the message. + Using endswith so we don't need to hardcode the constant. Co-authored-by: wookie184 --- bot/exts/utils/snekbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index 7ee5c5d21..1c0896804 100644 --- a/bot/exts/utils/snekbox.py +++ b/bot/exts/utils/snekbox.py @@ -347,7 +347,7 @@ class Snekbox(Cog): warning_message = "" # 33 is the length of the error message. It is done to make sure the last line of output contains # the error and the error is not manually printed by the author with a syntax error. - if "EOFError: EOF when reading a line" in output[-33:] and results['returncode'] == 1: + if results["stdout"].rstrip().endswith("EOFError: EOF when reading a line") and results["returncode"] == 1: warning_message += ":warning: Note: `input` is not supported by the bot :warning:\n\n" icon = self.get_status_emoji(results) -- cgit v1.2.3 From f3c103856190f360bf1bcd4378e05ea7a5b22a74 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Fri, 3 Mar 2023 01:57:14 +0530 Subject: Edit comment to match wookie's review --- bot/exts/utils/snekbox.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/exts/utils/snekbox.py b/bot/exts/utils/snekbox.py index 1c0896804..ddcbe01fa 100644 --- a/bot/exts/utils/snekbox.py +++ b/bot/exts/utils/snekbox.py @@ -345,8 +345,9 @@ class Snekbox(Cog): output, paste_link = await self.format_output(results["stdout"]) warning_message = "" - # 33 is the length of the error message. It is done to make sure the last line of output contains - # the error and the error is not manually printed by the author with a syntax error. + + # This is done to make sure the last line of output contains the error + # and the error is not manually printed by the author with a syntax error. if results["stdout"].rstrip().endswith("EOFError: EOF when reading a line") and results["returncode"] == 1: warning_message += ":warning: Note: `input` is not supported by the bot :warning:\n\n" -- cgit v1.2.3