diff options
author | 2024-07-08 17:36:27 -0500 | |
---|---|---|
committer | 2024-07-08 17:36:27 -0500 | |
commit | 9063b750ff2aace7cb12b264eb6f11edc68e1e7f (patch) | |
tree | bf2638231c923cc22e65c979479c11026e0b1518 /bot/exts/fun/latex.py | |
parent | Disable Poetry package mode (diff) | |
parent | Display word on hangman timeout (#1561) (diff) |
Merge branch 'main' into br/gh1560br/gh1560
Diffstat (limited to 'bot/exts/fun/latex.py')
-rw-r--r-- | bot/exts/fun/latex.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/bot/exts/fun/latex.py b/bot/exts/fun/latex.py index 13b3c503..5ce60fa1 100644 --- a/bot/exts/fun/latex.py +++ b/bot/exts/fun/latex.py @@ -8,9 +8,10 @@ from typing import BinaryIO import discord from PIL import Image -from aiohttp import client_exceptions, web +from aiohttp import client_exceptions 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 Channels, WHITELISTED_CHANNELS @@ -100,17 +101,16 @@ class Latex(commands.Cog): async def _upload_to_pastebin(self, text: str) -> str | None: """Uploads `text` to the paste service, returning the url if successful.""" + file = PasteFile(content=text, lexer="text") try: - async with self.bot.http_session.post( - PASTEBIN_URL + "/documents", - data=text, - raise_for_status=True - ) as response: - response_json = await response.json() - if "key" in response_json: - return f"{PASTEBIN_URL}/{response_json['key']}.txt?noredirect" - except web.HTTPClientError as e: + resp = await send_to_paste_service( + files=[file], + http_session=self.bot.http_session, + ) + return resp.link + except (PasteTooLongError, PasteUploadError) as e: log.info("Error when uploading latex output to pastebin. %s", e) + return None async def _prepare_error_embed(self, err: InvalidLatexError | LatexServerError | None) -> discord.Embed: title = "Server encountered an issue, please retry later." |