Skip to content

Commit c0cd219

Browse files
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
1 parent a0e6853 commit c0cd219

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

bot/decorators.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import arrow
88
import discord
9-
from aiohttp import ClientSession
109
from discord import Member, NotFound
1110
from discord.ext import commands
1211
from discord.ext.commands import Cog, Context
@@ -159,17 +158,16 @@ async def inner(self: Cog, ctx: Context, *args, **kwargs) -> None:
159158

160159
paste_response = None
161160
if RedirectOutput.delete_invocation:
162-
async with ClientSession() as session:
163-
try:
164-
paste_response = await send_to_paste_service(
165-
files=[PasteFile(content=ctx.message.content, lexer="markdown")],
166-
http_session=session,
167-
)
168-
except PasteUploadError:
169-
log.exception(
170-
"Failed to upload message %d in channel %d to paste service when redirecting output",
171-
ctx.message.id, ctx.message.channel.id
172-
)
161+
try:
162+
paste_response = await send_to_paste_service(
163+
files=[PasteFile(content=ctx.message.content, lexer="markdown")],
164+
http_session=ctx.bot.http_session,
165+
)
166+
except PasteUploadError:
167+
log.exception(
168+
"Failed to upload message %d in channel %d to paste service when redirecting output",
169+
ctx.message.id, ctx.message.channel.id
170+
)
173171

174172
msg = "Here's the output of "
175173
msg += f"[your command]({paste_response.link})" if paste_response else "your command"

bot/exts/utils/attachment_pastebin_uploader.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import re
44

5-
import aiohttp
65
import discord
76
from discord.ext import commands
87
from pydis_core.utils import paste_service
@@ -116,8 +115,7 @@ async def on_message(self, message: discord.Message) -> None:
116115
# Upload the files to the paste bin, exiting early if there's an error.
117116
log.trace(f"Attempting to upload {len(files)} file(s) to pastebin.")
118117
try:
119-
async with aiohttp.ClientSession() as session:
120-
paste_response = await paste_service.send_to_paste_service(files=files, http_session=session)
118+
paste_response = await paste_service.send_to_paste_service(files=files, http_session=self.bot.http_session)
121119
except (paste_service.PasteTooLongError, ValueError):
122120
log.trace(f"{message.author}'s attachments were too long.")
123121
await bot_reply.edit(content="Your paste is too long, and couldn't be uploaded.")
@@ -145,8 +143,7 @@ async def on_message(self, message: discord.Message) -> None:
145143
return
146144

147145
# Delete the paste and the bot's message.
148-
async with aiohttp.ClientSession() as session:
149-
await session.get(paste_response.removal)
146+
await self.bot.http_session.get(paste_response.removal)
150147

151148
await bot_reply.delete()
152149

0 commit comments

Comments
 (0)