Skip to content

Commit 06d4e5d

Browse files
fix: upload files in a seperate message to allow message previewing
this doesn't really benefit mobile though
1 parent 4ca20cc commit 06d4e5d

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

monty/exts/core/eval.py

Lines changed: 18 additions & 18 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):
@@ -340,14 +336,16 @@ async def ieval(self, ctx: commands.Context, *, body: str) -> None:
340336
delete_contexts = (ctx.message, None)
341337
else:
342338
delete_contexts = (None,)
343-
response.components += [
339+
delete_components = [
344340
disnake.ui.ActionRow(
345341
*[DeleteButton(ctx.author.id, allow_manage_messages=False, initial_message=m) for m in delete_contexts]
346342
)
347343
]
348-
await ctx.send(
349-
allowed_mentions=disnake.AllowedMentions.none(), components=response.components, files=response.files
350-
)
344+
if response.components:
345+
response.components += delete_components
346+
await ctx.send(allowed_mentions=disnake.AllowedMentions.none(), components=response.components)
347+
if response.files:
348+
await ctx.send(files=response.files, components=delete_components)
351349

352350
@commands.command(name="repl", hidden=True)
353351
async def repl(self, ctx: commands.Context) -> None:
@@ -436,20 +434,22 @@ async def repl(self, ctx: commands.Context) -> None:
436434
delete_contexts = (msg, None)
437435
else:
438436
delete_contexts = (None,)
439-
response.components += [
437+
delete_components = [
440438
disnake.ui.ActionRow(
441439
*[
442440
DeleteButton(ctx.author.id, allow_manage_messages=False, initial_message=m)
443441
for m in delete_contexts
444442
]
445443
)
446444
]
447-
await ctx.reply(
448-
allowed_mentions=disnake.AllowedMentions.none(),
449-
components=response.components,
450-
files=response.files,
451-
fail_if_not_exists=False,
452-
)
445+
if response.components:
446+
response.components += delete_components
447+
await ctx.send(
448+
allowed_mentions=disnake.AllowedMentions.none(),
449+
components=response.components,
450+
)
451+
if response.files:
452+
await ctx.send(files=response.files, components=delete_components)
453453
local_vars = result.local_vars
454454

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

0 commit comments

Comments
 (0)