feat(discord-bot): screenshots placeholder message to edit
This commit is contained in:
@@ -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 (attachments) {
|
||||
await channel.send({ files: attachments.map(a => a.url) });
|
||||
|
||||
if (report.screenshotsMessageId) {
|
||||
try {
|
||||
const screenshotsMsg = await channel.messages.fetch(report.screenshotsMessageId);
|
||||
if (attachments) {
|
||||
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é." });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user