Skip to content

Commit

Permalink
Move Snekbox to new pastebin
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <noreply@github.com>
  • Loading branch information
shenanigansd authored Apr 15, 2024
1 parent 06047c4 commit 0ab51c4
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/bot/exts/utilities/snekbox/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
from pydis_core.utils.regex import FORMATTED_CODE_REGEX, RAW_CODE_REGEX

from bot.bot import Bot
from bot.constants import MODERATION_ROLES, TXT_LIKE_FILES, Emojis, URLs
from bot.constants import MODERATION_ROLES, TXT_LIKE_FILES, BaseURLs, Emojis, URLs
from bot.log import get_logger
from bot.utils import send_to_paste_service
from bot.utils.lock import LockedResourceError, lock_arg
from bot.utils.services import PasteTooLongError, PasteUploadError
from pydis_core.utils.paste_service import PasteFile, send_to_paste_service
from pydis_core.utils import interactions, paste_service

from ._eval import EvalJob, EvalResult
from ._io import FileAttachment
Expand Down Expand Up @@ -223,21 +224,21 @@ async def post_job(self: Self, job: EvalJob) -> EvalResult:
) as resp:
return EvalResult.from_dict(await resp.json())

@staticmethod
async def upload_output(http_session: ClientSession, output: str) -> str | None:
async def upload_output(self, output: str) -> str | None:
"""Upload the job's output to a paste service and return a URL to it if successful."""
log.trace("Uploading full output to paste service...")

file = PasteFile(content=output, lexer="text")
try:
return await send_to_paste_service(
http_session,
output,
extension="txt",
max_length=MAX_PASTE_LENGTH,
paste_response = await send_to_paste_service(
files=[file],
http_session=self.bot.http_session,
paste_url=BaseURLs.paste_url,
)
except PasteTooLongError:
return paste_response.link
except paste_service.PasteTooLongError:
return "too long to upload"
except PasteUploadError:
except paste_service.PasteUploadError:
return "unable to upload"

@staticmethod
Expand Down Expand Up @@ -279,10 +280,7 @@ async def format_output(
output = output.replace("<!@", "<!@\u200b") # Zero-width space

if ESCAPE_REGEX.findall(output):
paste_link = await self.upload_output(
self.bot.http_session,
original_output,
)
paste_link = await self.upload_output(original_output)
return (
"Code block escape attempt detected; will not output result",
paste_link,
Expand All @@ -308,10 +306,7 @@ async def format_output(
output = f"{output[:max_chars]}\n... (truncated - too long)"

if truncated:
paste_link = await self.upload_output(
self.bot.http_session,
original_output,
)
paste_link = await self.upload_output(original_output)

if output_default and not output:
output = output_default
Expand Down

0 comments on commit 0ab51c4

Please sign in to comment.