Skip to content

Commit

Permalink
fix/travel tickets (#1263)
Browse files Browse the repository at this point in the history
* fix: trim decline message boundary from activities

* fix: don't allow changing countries in DMs

* fix: everything falling apart when approving
  • Loading branch information
geisterfurz007 authored Mar 16, 2024
1 parent 6a5abcb commit d154eb4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
19 changes: 18 additions & 1 deletion src/programs/tickets/travel/travel-data-message-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*/) ?? [];
Expand Down
15 changes: 12 additions & 3 deletions src/programs/tickets/travel/travel-editing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class TravelEditing {
details: TripDetails,
interaction:
| MessageComponentInteraction
| ModalMessageModalSubmitInteraction
| ModalMessageModalSubmitInteraction,
countriesEnabled = true
): Promise<EditResult> {
const userId = interaction.user.id;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d154eb4

Please sign in to comment.