all repos — stealth-developers @ 177530ec8ef12acd4a8d923b731a77bdf8e3da72

bot(tickets): delete attachments when message is deleted
vi did:web:vt3e.cat
Fri, 03 Jul 2026 21:39:01 +0100
commit

177530ec8ef12acd4a8d923b731a77bdf8e3da72

parent

3730c396e5f98ab5f0415bcb62f978689a5ff938

2 files changed, 19 insertions(+), 0 deletions(-)

jump to
M apps/bot/src/feats/tickets/listeners.tsapps/bot/src/feats/tickets/listeners.ts

@@ -8,6 +8,7 @@ createTicketMessageWithAttachments,

deleteTicketMessage, editTicket, editTicketMessage, + getTicketAttachmentsByMessageId, getTicketByChannelId, getTicketMessageByMessageId, } from "@stealth-developers/db";

@@ -220,6 +221,20 @@ if (message.flags.has("Ephemeral")) return;

const dbMessage = await getTicketMessageByMessageId(message.id); if (!dbMessage) return; + + const attachments = await getTicketAttachmentsByMessageId(dbMessage.id); + if (attachments && attachments.length > 0) { + for (const attachment of attachments) { + const file = s3.file(attachment.key); + const deleteRes = await Result.fromAsync(file.delete()); + if (deleteRes.isErr()) { + logger.error( + deleteRes.unwrapErr(), + `Failed to delete S3 attachment file with key: ${attachment.key}`, + ); + } + } + } await deleteTicketMessage(dbMessage.id); });
M pkgs/db/src/utils/ticket.tspkgs/db/src/utils/ticket.ts

@@ -141,6 +141,10 @@ with: ticketWithRelations,

}); } +export const getTicketAttachmentsByMessageId = async (messageId: string) => { + return db.select().from(ticketAttachments).where(eq(ticketAttachments.messageId, messageId)); +}; + export async function getOpenTickets(): Promise<TicketWithRelations[]> { return await db.query.tickets.findMany({ where: {