diff options
author | 2024-07-04 23:54:25 +0100 | |
---|---|---|
committer | 2024-07-04 22:54:25 +0000 | |
commit | 6207352ecc115b3dc030693c82ebfc4920453525 (patch) | |
tree | ad4f0ca850e8a3fb3c2c1415cc66bfb9b17a9671 /bot/exts/core | |
parent | Bump ruff from 0.4.10 to 0.5.0 (#1565) (diff) |
Update internal eval & latex to use the new paste service API (#1558)
Diffstat (limited to 'bot/exts/core')
-rw-r--r-- | bot/exts/core/internal_eval/_internal_eval.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py index 39ce558a..15db8d40 100644 --- a/bot/exts/core/internal_eval/_internal_eval.py +++ b/bot/exts/core/internal_eval/_internal_eval.py @@ -4,6 +4,7 @@ import textwrap import discord from discord.ext import commands from pydis_core.utils.logging import get_logger +from pydis_core.utils.paste_service import PasteFile, PasteTooLongError, PasteUploadError, send_to_paste_service from bot.bot import Bot from bot.constants import Client, Roles @@ -86,17 +87,16 @@ class InternalEval(commands.Cog): async def _upload_output(self, output: str) -> str | None: """Upload `internal eval` output to our pastebin and return the url.""" data = self.shorten_output(output, max_length=MAX_LENGTH) + file = PasteFile(content=data, lexer="text") try: - async with self.bot.http_session.post( - "https://paste.pythondiscord.com/documents", data=data, raise_for_status=True - ) as resp: - data = await resp.json() - - if "key" in data: - return f"https://paste.pythondiscord.com/{data['key']}" - except Exception: - # 400 (Bad Request) means there are too many characters + resp = await send_to_paste_service( + files=[file], + http_session=self.bot.http_session, + ) + return resp.link + except (PasteTooLongError, PasteUploadError): log.exception("Failed to upload `internal eval` output to paste service!") + return None async def _send_output(self, ctx: commands.Context, output: str) -> None: """Send the `internal eval` output to the command invocation context.""" |