mirror of
https://github.com/FranP-code/shopping-discord-bot.git
synced 2025-10-13 00:22:44 +00:00
added truncation for productName
This commit is contained in:
@@ -2,6 +2,10 @@ const { SlashCommandSubcommandBuilder, hyperlink, bold, ActionRowBuilder, Button
|
|||||||
const puppeteer = require('puppeteer');
|
const puppeteer = require('puppeteer');
|
||||||
const jsdom = require('jsdom');
|
const jsdom = require('jsdom');
|
||||||
|
|
||||||
|
function truncateText(text, max) {
|
||||||
|
return text.substr(0, max - 1).trim() + (text.length > max ? '...' : '');
|
||||||
|
}
|
||||||
|
|
||||||
const countryData = {
|
const countryData = {
|
||||||
'ar': {
|
'ar': {
|
||||||
name: 'Argentina',
|
name: 'Argentina',
|
||||||
@@ -171,8 +175,9 @@ module.exports = {
|
|||||||
.querySelector(countryPage.selectors.link)
|
.querySelector(countryPage.selectors.link)
|
||||||
.getAttribute('href')
|
.getAttribute('href')
|
||||||
.replace(/.*\/\/[^/]*/, '');
|
.replace(/.*\/\/[^/]*/, '');
|
||||||
|
const productName = element.querySelector(countryPage.selectors.title).textContent;
|
||||||
const link = hyperlink(
|
const link = hyperlink(
|
||||||
element.querySelector(countryPage.selectors.title).textContent,
|
truncateText(productName, 100),
|
||||||
countryPage.productUrl.replace('%S', encodeURI(productRelativePath)),
|
countryPage.productUrl.replace('%S', encodeURI(productRelativePath)),
|
||||||
);
|
);
|
||||||
const priceNumber = element.querySelector(countryPage.selectors.price).textContent.replace('$', '').replace(' ', '');
|
const priceNumber = element.querySelector(countryPage.selectors.price).textContent.replace('$', '').replace(' ', '');
|
||||||
@@ -202,7 +207,6 @@ module.exports = {
|
|||||||
.setStyle(ButtonStyle.Link),
|
.setStyle(ButtonStyle.Link),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
const replyTexts = [
|
const replyTexts = [
|
||||||
`${responses.extractedFrom[userLanguage]} ${pagesScraped.map(({ name }) => name).join(' ')}`,
|
`${responses.extractedFrom[userLanguage]} ${pagesScraped.map(({ name }) => name).join(' ')}`,
|
||||||
`${productPrices.join('\n')}`,
|
`${productPrices.join('\n')}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user