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