diff options
author | 2025-09-23 11:55:36 -0400 | |
---|---|---|
committer | 2025-09-23 16:55:36 +0100 | |
commit | c0cd219c52316e35a70e42eef36ca5d11382f762 (patch) | |
tree | 3a09c6c593d68a91e219caa3f9026945b48d7643 | |
parent | Preserve Invocation Context (#3377) (diff) |
fix: don't create a new session to upload to the pastebin (#3388)
* fix: don't create a new session to upload to the pastebin
noticed this earlier but didn't see it get fixed
this is a simple fix that lessens creating an
unnecessary session
* fix the other two instances
https://discord.com/channels/267624335836053506/291284109232308226/1419909021460336680
-rw-r--r-- | bot/decorators.py | 22 | ||||
-rw-r--r-- | bot/exts/utils/attachment_pastebin_uploader.py | 7 |
2 files changed, 12 insertions, 17 deletions
diff --git a/bot/decorators.py b/bot/decorators.py index 8a29a67d5..d39c1cc33 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -6,7 +6,6 @@ from contextlib import suppress import arrow import discord -from aiohttp import ClientSession from discord import Member, NotFound from discord.ext import commands from discord.ext.commands import Cog, Context @@ -159,17 +158,16 @@ def redirect_output( paste_response = None if RedirectOutput.delete_invocation: - async with ClientSession() as session: - try: - paste_response = await send_to_paste_service( - files=[PasteFile(content=ctx.message.content, lexer="markdown")], - http_session=session, - ) - except PasteUploadError: - log.exception( - "Failed to upload message %d in channel %d to paste service when redirecting output", - ctx.message.id, ctx.message.channel.id - ) + try: + paste_response = await send_to_paste_service( + files=[PasteFile(content=ctx.message.content, lexer="markdown")], + http_session=ctx.bot.http_session, + ) + except PasteUploadError: + log.exception( + "Failed to upload message %d in channel %d to paste service when redirecting output", + ctx.message.id, ctx.message.channel.id + ) msg = "Here's the output of " msg += f"[your command]({paste_response.link})" if paste_response else "your command" diff --git a/bot/exts/utils/attachment_pastebin_uploader.py b/bot/exts/utils/attachment_pastebin_uploader.py index 03439390b..9a805dd66 100644 --- a/bot/exts/utils/attachment_pastebin_uploader.py +++ b/bot/exts/utils/attachment_pastebin_uploader.py @@ -2,7 +2,6 @@ from __future__ import annotations import re -import aiohttp import discord from discord.ext import commands from pydis_core.utils import paste_service @@ -116,8 +115,7 @@ class AutoTextAttachmentUploader(commands.Cog): # Upload the files to the paste bin, exiting early if there's an error. log.trace(f"Attempting to upload {len(files)} file(s) to pastebin.") try: - async with aiohttp.ClientSession() as session: - paste_response = await paste_service.send_to_paste_service(files=files, http_session=session) + paste_response = await paste_service.send_to_paste_service(files=files, http_session=self.bot.http_session) except (paste_service.PasteTooLongError, ValueError): log.trace(f"{message.author}'s attachments were too long.") await bot_reply.edit(content="Your paste is too long, and couldn't be uploaded.") @@ -145,8 +143,7 @@ class AutoTextAttachmentUploader(commands.Cog): return # Delete the paste and the bot's message. - async with aiohttp.ClientSession() as session: - await session.get(paste_response.removal) + await self.bot.http_session.get(paste_response.removal) await bot_reply.delete() |