Skip to content

Commit b592065

Browse files
committed
download sage img
1 parent 9c41a3d commit b592065

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/service/sageExecution.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ const executeSage = async function(interaction){
2929
await interaction.deferReply();
3030

3131
return client.askSage(code)
32-
.then(res => {
32+
.then(async res => {
3333
embed.description = "Input:\n```py\n" + code + "\n```\nOutput:\n```\n" + (
3434
res?.result?.["text/plain"]?.trim() || res?.stdout?.trim() || (res.result?.image ? "Image Below" : "No Output")
3535
) + "\n```";
3636

37-
if (res?.result?.image){ // @ts-ignore
38-
embed.image = { url: res.result.image };
37+
if (res?.result?.image){
38+
const imageRes = await fetch(res.result.image);
39+
if (imageRes.ok){
40+
const buffer = await imageRes.arrayBuffer();
41+
const attachment = {
42+
attachment: Buffer.from(buffer),
43+
name: `sage_output_${interaction.id}.png`,
44+
};
45+
// @ts-ignore
46+
embed.image = { url: `attachment://${attachment.name}` };
47+
return await interaction.editReply({ embeds: [embed], files: [attachment] });
48+
}
3949
}
4050

4151
return interaction.editReply({ embeds: [embed]});

0 commit comments

Comments
 (0)