refactoring and adding limit command option

This commit is contained in:
2023-01-14 21:44:02 -03:00
parent 205b865592
commit 25bd8f306b
9 changed files with 159 additions and 130 deletions

View File

@@ -0,0 +1,12 @@
const { responsesTexts } = require('../utils/constants');
function generateLocalizedResponses(userLanguage) {
const responsesEntries = Object.entries(responsesTexts);
const localizatedResponses = {};
responsesEntries.forEach(([responseName, responseTexts]) => {
localizatedResponses[responseName] = Object.entries(responseTexts).find(responseText => responseText[0] === userLanguage)[1];
});
return localizatedResponses;
}
module.exports = generateLocalizedResponses;

View File

@@ -0,0 +1,5 @@
function getRandomElementFromArray(arr) {
return arr[Math.floor((Math.random() * arr.length))];
}
module.exports = getRandomElementFromArray;

5
scripts/truncateText.js Normal file
View File

@@ -0,0 +1,5 @@
function truncateText(text, max) {
return text.substr(0, max - 1).trim() + (text.length > max ? '...' : '');
}
module.exports = truncateText;