From 0ab51c4b2185567d157bf28b06e702ea4ec55c3b Mon Sep 17 00:00:00 2001 From: Bradley Reynolds Date: Mon, 15 Apr 2024 20:26:36 +0000 Subject: [PATCH] Move Snekbox to new pastebin Signed-off-by: GitHub --- src/bot/exts/utilities/snekbox/_cog.py | 33 +++++++++++--------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/bot/exts/utilities/snekbox/_cog.py b/src/bot/exts/utilities/snekbox/_cog.py index bbb58b6..1ffa74d 100644 --- a/src/bot/exts/utilities/snekbox/_cog.py +++ b/src/bot/exts/utilities/snekbox/_cog.py @@ -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 @@ -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 @@ -279,10 +280,7 @@ async def format_output( output = output.replace("