From d61f58ee972073332cf3f66d928c2852c770042f Mon Sep 17 00:00:00 2001 From: Koerismo Date: Thu, 17 Jul 2025 17:18:40 -0400 Subject: [PATCH] Unescape newlines and tabs on response creation --- src/commands/guild/responses.ts | 4 +++- src/utils/utils.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/commands/guild/responses.ts b/src/commands/guild/responses.ts index 7612de7..1eaa17a 100644 --- a/src/commands/guild/responses.ts +++ b/src/commands/guild/responses.ts @@ -6,6 +6,7 @@ import { LogLevelColor } from '../../utils/log'; import { PermissionLevel } from '../../utils/permissions'; import * as persist from '../../utils/persist'; +import { unescapeSpecialCharacters } from '../../utils/utils'; const Responses: Command = { permissionLevel: PermissionLevel.MODERATOR, @@ -77,7 +78,8 @@ const Responses: Command = { return interaction.reply({ content: `There is already a response with ID "${responseID}"!`, ephemeral: true }); } - data.responses[responseID] = interaction.options.getString('contents', true); + const responseContents = interaction.options.getString('contents', true); + data.responses[responseID] = unescapeSpecialCharacters(responseContents); persist.saveData(interaction.guild.id); return interaction.reply({ content: 'Added response.', ephemeral: true }); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 854e020..1847141 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -60,6 +60,12 @@ export function escapeSpecialCharacters(raw: string) { .replaceAll('-', '\\-'); // list } +export function unescapeSpecialCharacters(escaped: string) { + return escaped + .replaceAll('\\n', '\n') + .replaceAll('\\t', '\t'); +} + export async function streamToBuffer(stream: Stream) { return new Promise((resolve, reject) => { const buf = Array();