feat(discord-bot): screenshots placeholder message to edit
All checks were successful
Build and Push Docker Image / typecheck (push) Successful in 26s
Build and Push Docker Image / build (push) Successful in 35s

This commit is contained in:
2026-05-12 20:01:38 +02:00
parent d679a63d3d
commit d76ac73d84

View File

@@ -184,11 +184,12 @@ export const handleReportModal = async (interaction: ModalSubmitInteraction, cli
components: [reportActionRow(inserted.id)],
});
messageLink = `https://discord.com/channels/${reportChannel.guild.id}/${reportChannel.id}/${reportMessage.id}`;
await db.update(tables.reports).set({ messageLink }).where(eq(tables.reports.id, inserted.id));
if (attachments) {
const screenshotsMessage = await reportChannel.send({ files: attachments.map(a => a.url) });
await db.update(tables.reports).set({ screenshotsMessageId: screenshotsMessage.id }).where(eq(tables.reports.id, inserted.id));
}
const screenshotsMessage = attachments
? await reportChannel.send({ files: attachments.map(a => a.url) })
: await reportChannel.send({ content: "-# Pas de screenshots" });
await db.update(tables.reports)
.set({ messageLink, screenshotsMessageId: screenshotsMessage.id })
.where(eq(tables.reports.id, inserted.id));
} else {
logger.error("Invalid 'DISCORD_REPORT_CHANNEL'");
}
@@ -256,11 +257,6 @@ export const handleEditModal = async (interaction: ModalSubmitInteraction, clien
return;
}
const updateData: { reason: string; screenshots?: string | null } = { reason };
if (screenshotUrls !== null) updateData.screenshots = screenshotUrls;
await db.update(tables.reports).set(updateData).where(eq(tables.reports.id, reportId));
const channel = await client.channels.fetch(channelId);
if (channel?.type === ChannelType.GuildText) {
try {
@@ -272,10 +268,24 @@ export const handleEditModal = async (interaction: ModalSubmitInteraction, clien
} catch {
logger.error("Failed to fetch/edit report message");
}
if (report.screenshotsMessageId) {
try {
const screenshotsMsg = await channel.messages.fetch(report.screenshotsMessageId);
if (attachments) {
await channel.send({ files: attachments.map(a => a.url) });
await screenshotsMsg.edit({ content: "", files: attachments.map(a => a.url), attachments: [] });
} else {
await screenshotsMsg.edit({ content: "-# Pas de screenshots", attachments: [] });
}
} catch {
logger.error("Failed to edit screenshots message");
}
}
}
await db.update(tables.reports)
.set({ reason, screenshots: screenshotUrls })
.where(eq(tables.reports.id, reportId));
await interaction.editReply({ content: "Signalement modifié." });
};