From a09d308c1f12341b7a4a76146e56b0b7488b73d8 Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Sat, 12 Nov 2022 18:02:42 -0300 Subject: [PATCH] added truncation for productName --- commands/price.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commands/price.js b/commands/price.js index e90e329..e698456 100644 --- a/commands/price.js +++ b/commands/price.js @@ -2,6 +2,10 @@ const { SlashCommandSubcommandBuilder, hyperlink, bold, ActionRowBuilder, Button const puppeteer = require('puppeteer'); const jsdom = require('jsdom'); +function truncateText(text, max) { + return text.substr(0, max - 1).trim() + (text.length > max ? '...' : ''); +} + const countryData = { 'ar': { name: 'Argentina', @@ -171,8 +175,9 @@ module.exports = { .querySelector(countryPage.selectors.link) .getAttribute('href') .replace(/.*\/\/[^/]*/, ''); + const productName = element.querySelector(countryPage.selectors.title).textContent; const link = hyperlink( - element.querySelector(countryPage.selectors.title).textContent, + truncateText(productName, 100), countryPage.productUrl.replace('%S', encodeURI(productRelativePath)), ); const priceNumber = element.querySelector(countryPage.selectors.price).textContent.replace('$', '').replace(' ', ''); @@ -202,7 +207,6 @@ module.exports = { .setStyle(ButtonStyle.Link), )), ); - const replyTexts = [ `${responses.extractedFrom[userLanguage]} ${pagesScraped.map(({ name }) => name).join(' ')}`, `${productPrices.join('\n')}`,