From 070825d2b779b114a1c345fbca210d324bf34d53 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sat, 29 Mar 2025 22:19:55 -0400 Subject: Quote submit stats + input validation for author/year; API changes; Use toString for some stuff --- bot/src/commands/quote.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'bot/src/commands/quote.js') diff --git a/bot/src/commands/quote.js b/bot/src/commands/quote.js index 55b8cbc..9c409f9 100644 --- a/bot/src/commands/quote.js +++ b/bot/src/commands/quote.js @@ -50,6 +50,7 @@ export default { .setCustomId('authorImage') .setLabel('Submit the image of the author') .setMaxLength(100) + .setMinLength(4) .setPlaceholder('Image URL (512x512) or (128x128)') .setStyle(TextInputStyle.Short); @@ -57,6 +58,7 @@ export default { .setCustomId('quote') .setLabel('Enter the quote') .setMaxLength(200) + .setMinLength(5) .setPlaceholder('Quote') .setStyle(TextInputStyle.Paragraph); @@ -85,6 +87,29 @@ export default { const quote = modalInteraction.fields.getTextInputValue('quote'); const year = modalInteraction.fields.getTextInputValue('year'); + try { + new URL(authorImage); + } catch { + return modalInteraction.reply({ + content: 'Error: Author image must be a valid URL.', + flags: MessageFlags.Ephemeral + }); + } + + if (!authorImage.match(/\.(jpeg|jpg|png|webp)$/i)) { + return modalInteraction.reply({ + content: 'Error: Author image URL must end with a valid image extension (jpeg, jpg, png, webp).', + flags: MessageFlags.Ephemeral + }); + } + + if (isNaN(year) || year.trim() === '' || !Number.isInteger(Number(year))) { + return modalInteraction.reply({ + content: 'Error: Year must be a number.', + flags: MessageFlags.Ephemeral + }); + } + await pendingQuote.create({ author: author, authorImage: authorImage, -- cgit v1.2.3