diff --git a/apps/discord-bot/src/reporting.ts b/apps/discord-bot/src/reporting.ts index 01fd5ec..fcdf2a4 100644 --- a/apps/discord-bot/src/reporting.ts +++ b/apps/discord-bot/src/reporting.ts @@ -186,7 +186,8 @@ export const handleReportModal = async (interaction: ModalSubmitInteraction, cli 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) { - await reportChannel.send({ files: attachments.map(a => a.url) }); + 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)); } } else { logger.error("Invalid 'DISCORD_REPORT_CHANNEL'"); @@ -225,6 +226,16 @@ export const handleDeleteButton = async (interaction: ButtonInteraction, reportI } await db.delete(tables.reports).where(eq(tables.reports.id, reportId)); + + if (report.screenshotsMessageId) { + try { + const screenshotsMsg = await interaction.message.channel.messages.fetch(report.screenshotsMessageId); + await screenshotsMsg.delete(); + } catch { + // already deleted or not found + } + } + await interaction.message.delete(); await interaction.editReply({ content: "Signalement supprimé." }); }; diff --git a/packages/database/drizzle/0003_uneven_mephistopheles.sql b/packages/database/drizzle/0003_uneven_mephistopheles.sql new file mode 100644 index 0000000..16f0d38 --- /dev/null +++ b/packages/database/drizzle/0003_uneven_mephistopheles.sql @@ -0,0 +1 @@ +ALTER TABLE "reports" ADD COLUMN "screenshots_message_id" text; \ No newline at end of file diff --git a/packages/database/drizzle/meta/0003_snapshot.json b/packages/database/drizzle/meta/0003_snapshot.json new file mode 100644 index 0000000..bb0571d --- /dev/null +++ b/packages/database/drizzle/meta/0003_snapshot.json @@ -0,0 +1,220 @@ +{ + "id": "a19383ff-8e7a-4da4-8c29-888e8ea9f670", + "prevId": "4643e6bd-db18-44c9-893d-8f57a94e8c0a", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.accounts": { + "name": "accounts", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "balance": { + "name": "balance", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reports": { + "name": "reports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "reporter_id": { + "name": "reporter_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reporter_username": { + "name": "reporter_username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "player_name": { + "name": "player_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "player_id": { + "name": "player_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "screenshots": { + "name": "screenshots", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message_link": { + "name": "message_link", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "screenshots_message_id": { + "name": "screenshots_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tracked_players": { + "name": "tracked_players", + "schema": "", + "columns": { + "player_id": { + "name": "player_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.username_history": { + "name": "username_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "player_id": { + "name": "player_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "username_history_player_id_tracked_players_player_id_fk": { + "name": "username_history_player_id_tracked_players_player_id_fk", + "tableFrom": "username_history", + "tableTo": "tracked_players", + "columnsFrom": [ + "player_id" + ], + "columnsTo": [ + "player_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/database/drizzle/meta/_journal.json b/packages/database/drizzle/meta/_journal.json index 9b79311..24eb97c 100644 --- a/packages/database/drizzle/meta/_journal.json +++ b/packages/database/drizzle/meta/_journal.json @@ -22,6 +22,13 @@ "when": 1778605638295, "tag": "0002_lucky_praxagora", "breakpoints": true + }, + { + "idx": 3, + "version": "7", + "when": 1778607030657, + "tag": "0003_uneven_mephistopheles", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/database/src/schema/tables.ts b/packages/database/src/schema/tables.ts index b7f5f95..ae47990 100644 --- a/packages/database/src/schema/tables.ts +++ b/packages/database/src/schema/tables.ts @@ -10,8 +10,9 @@ export const reports = pgTable("reports", { playerName: text("player_name").notNull(), playerId: text("player_id").notNull(), reason: text("reason").notNull(), - screenshots: text("screenshots"), - messageLink: text("message_link"), + screenshots: text("screenshots"), + messageLink: text("message_link"), + screenshotsMessageId: text("screenshots_message_id"), createdAt: timestamp("created_at").notNull().defaultNow(), });