aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-07-11 19:39:53 +0000
committerGravatar Gareth Coles <[email protected]>2018-07-11 19:39:53 +0000
commit6064e980864724af75de0a20ffcec8f839685b23 (patch)
treef9f3df10c35c095d90fa20bfd8d455eccf2bdd10
parent[Snekbox] Code template should activate snekbox prod VM (diff)
parentSend truncated output to pasting service (diff)
Merge branch 'momo/snekbox-paste' into 'master'
Send truncated output to pasting service See merge request python-discord/projects/bot!25
-rw-r--r--bot/cogs/snekbox.py29
-rw-r--r--bot/constants.py1
-rw-r--r--config-default.yml1
3 files changed, 28 insertions, 3 deletions
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py
index f49526884..6bc333ff6 100644
--- a/bot/cogs/snekbox.py
+++ b/bot/cogs/snekbox.py
@@ -5,6 +5,7 @@ import re
from discord.ext.commands import Bot, Context, command
from bot.cogs.rmq import RMQ
+from bot.constants import URLs
log = logging.getLogger(__name__)
@@ -70,6 +71,7 @@ class Snekbox:
async with ctx.typing():
message = await self.rmq.consume(str(ctx.author.id), **RMQ_ARGS)
+ paste_link = None
if isinstance(message, str):
output = str.strip(" \n")
@@ -82,6 +84,9 @@ class Snekbox:
if ESCAPE_REGEX.findall(output):
output = "Code block escape attempt detected; will not output result"
else:
+ # the original output, to send to a pasting service if needed
+ full_output = output
+ truncated = False
if output.count("\n") > 0:
output = [f"{i:03d} | {line}" for i, line in enumerate(output.split("\n"), start=1)]
output = "\n".join(output)
@@ -93,14 +98,32 @@ class Snekbox:
output = f"{output[:1000]}\n... (truncated - too long, too many lines)"
else:
output = f"{output}\n... (truncated - too many lines)"
+ truncated = True
elif len(output) >= 1000:
output = f"{output[:1000]}\n... (truncated - too long)"
+ truncated = True
+
+ if truncated:
+ try:
+ response = await self.bot.http_session.post(
+ URLs.paste_service.format(key="documents"),
+ data=full_output
+ )
+ data = await response.json()
+ if "key" in data:
+ paste_link = URLs.paste_service.format(key=data["key"])
+ except Exception:
+ log.exception("Failed to upload full output to paste service!")
if output.strip():
- await ctx.send(
- f"{ctx.author.mention} Your eval job has completed.\n\n```py\n{output}\n```"
- )
+ if paste_link:
+ msg = f"{ctx.author.mention} Your eval job has completed.\n\n```py\n{output}\n```" \
+ f"\nFull output: {paste_link}"
+ else:
+ msg = f"{ctx.author.mention} Your eval job has completed.\n\n```py\n{output}\n```"
+
+ await ctx.send(msg)
else:
await ctx.send(
f"{ctx.author.mention} Your eval job has completed.\n\n```py\n[No output]\n```"
diff --git a/bot/constants.py b/bot/constants.py
index 6433d068a..17ec1779e 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -263,6 +263,7 @@ class URLs(metaclass=YAMLGetter):
site_user_api: str
site_user_complete_api: str
status: str
+ paste_service: str
# Debug mode
diff --git a/config-default.yml b/config-default.yml
index 4402eb9f1..5b87f8d78 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -86,3 +86,4 @@ urls:
site_user_api: 'https://api.pythondiscord.com/bot/users'
site_user_complete_api: 'https://api.pythondiscord.com/bot/users/complete'
status: !ENV 'STATUS_URL'
+ paste_service: 'https://paste.pydis.com/{key}'