From d154eb44954adf9aa6be8ab61d6d36aae7d972cf Mon Sep 17 00:00:00 2001 From: geisterfurz007 Date: Sat, 16 Mar 2024 12:23:51 +0100 Subject: [PATCH] fix/travel tickets (#1263) * fix: trim decline message boundary from activities * fix: don't allow changing countries in DMs * fix: everything falling apart when approving --- .../travel/travel-data-message-converter.ts | 19 ++++++++++++++++++- src/programs/tickets/travel/travel-editing.ts | 15 ++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/programs/tickets/travel/travel-data-message-converter.ts b/src/programs/tickets/travel/travel-data-message-converter.ts index 8d88c81bb..c0676461f 100644 --- a/src/programs/tickets/travel/travel-data-message-converter.ts +++ b/src/programs/tickets/travel/travel-data-message-converter.ts @@ -23,8 +23,25 @@ export class TravelDataMessageConverter { **Activities**: ${details.activities}`; } + private static sanitizeMessageContent(messageContent: string): string { + const boundary = "---\n"; + const declinedMessageBoundaryStart = messageContent.indexOf(boundary); + const declinedMessageBoundaryEnd = messageContent.lastIndexOf(boundary); + + if (declinedMessageBoundaryStart === -1) return messageContent; + + return messageContent + .substring( + declinedMessageBoundaryStart + boundary.length, + declinedMessageBoundaryEnd === -1 + ? messageContent.length + : declinedMessageBoundaryEnd + ) + .trim(); + } + static fromMessage(message: Message, guild: Guild): TripDetails { - const content = message.content; + const content = this.sanitizeMessageContent(message.content); const countryNameMatch = /Hey (.*)!$/gm.exec(content); const countryNames = countryNameMatch?.at(1)?.split(/\s*,\s*/) ?? []; diff --git a/src/programs/tickets/travel/travel-editing.ts b/src/programs/tickets/travel/travel-editing.ts index 445585896..7b5177383 100644 --- a/src/programs/tickets/travel/travel-editing.ts +++ b/src/programs/tickets/travel/travel-editing.ts @@ -39,7 +39,8 @@ export class TravelEditing { details: TripDetails, interaction: | MessageComponentInteraction - | ModalMessageModalSubmitInteraction + | ModalMessageModalSubmitInteraction, + countriesEnabled = true ): Promise { const userId = interaction.user.id; @@ -73,7 +74,11 @@ export class TravelEditing { switch (buttonInteraction.customId) { case editId: - return await this.doEditing(details, buttonInteraction); + return await this.doEditing( + details, + buttonInteraction, + countriesEnabled + ); case doneId: return { details, interaction: buttonInteraction }; default: @@ -128,7 +133,11 @@ export class TravelEditing { const { details: newDetails, interaction: newDetailsInteraction } = await this.getNewDetails(details, selectionInteraction); - return await this.offerEditing(newDetails, newDetailsInteraction); + return await this.offerEditing( + newDetails, + newDetailsInteraction, + countriesEnabled + ); } private async getNewDetails(