Skip to content

Commit 80f0cc9

Browse files
fix: upload files in a seperate message to allow message previewing
this doesn't really benefit mobile though
1 parent af2bc55 commit 80f0cc9

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

monty/exts/core/eval.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def get_component_for_segment(
203203
title: str,
204204
language: str,
205205
display_colour: int | disnake.Colour | None = None,
206-
) -> tuple[disnake.ui.Container | list[Any], disnake.File | None]:
206+
) -> tuple[disnake.ui.Container | list[Any] | None, disnake.File | None]:
207207
"""Get a UI component for a given segment of text."""
208208
file = None
209209
file_tuple = self.maybe_file(content, prefix="output", suffix="txt")
@@ -212,16 +212,12 @@ def get_component_for_segment(
212212
file_tuple = self.maybe_file(content, prefix="output", suffix="txt")
213213
language = "py"
214214
if file_tuple:
215-
filename, file = file_tuple
216-
container = disnake.ui.Container(
217-
disnake.ui.TextDisplay(f"Output too long, sent as file `{filename}`."),
218-
disnake.ui.File(f"attachment://{filename}"),
219-
)
215+
_, file = file_tuple
216+
return None, file
220217
elif content.strip():
221218
container = disnake.ui.Container(disnake.ui.TextDisplay(f"**{title}:**\n```{language}\n{content}\n```"))
222219
else:
223220
container = disnake.ui.Container(disnake.ui.TextDisplay(f"**{title}:**\n*No output.*"))
224-
225221
if display_colour is None:
226222
display_colour = constants.Colours.python_yellow
227223
if isinstance(display_colour, int):
@@ -338,14 +334,16 @@ async def ieval(self, ctx: commands.Context, *, body: str) -> None:
338334
delete_contexts = (ctx.message, None)
339335
else:
340336
delete_contexts = (None,)
341-
response.components += [
337+
delete_components = [
342338
disnake.ui.ActionRow(
343339
*[DeleteButton(ctx.author.id, allow_manage_messages=False, initial_message=m) for m in delete_contexts]
344340
)
345341
]
346-
await ctx.send(
347-
allowed_mentions=disnake.AllowedMentions.none(), components=response.components, files=response.files
348-
)
342+
if response.components:
343+
response.components += delete_components
344+
await ctx.send(allowed_mentions=disnake.AllowedMentions.none(), components=response.components)
345+
if response.files:
346+
await ctx.send(files=response.files, components=delete_components)
349347

350348
@commands.command(name="repl", hidden=True)
351349
async def repl(self, ctx: commands.Context) -> None:
@@ -403,19 +401,22 @@ async def repl(self, ctx: commands.Context) -> None:
403401
if result.raw_value == last_result:
404402
result.raw_value = None
405403
response = self.get_formatted_response(result)
406-
response.components += [
404+
delete_components = [
407405
disnake.ui.ActionRow(
408406
*[
409407
DeleteButton(ctx.author.id, allow_manage_messages=False, initial_message=m)
410408
for m in (ctx.message, None)
411409
]
412410
)
413411
]
414-
await ctx.send(
415-
allowed_mentions=disnake.AllowedMentions.none(),
416-
components=response.components,
417-
files=response.files,
418-
)
412+
if response.components:
413+
response.components += delete_components
414+
await ctx.send(
415+
allowed_mentions=disnake.AllowedMentions.none(),
416+
components=response.components,
417+
)
418+
if response.files:
419+
await ctx.send(files=response.files, components=delete_components)
419420
local_vars = result.local_vars
420421

421422
async def cog_check(self, ctx: commands.Context) -> bool:

0 commit comments

Comments
 (0)