Message generator update
This commit is contained in:
@@ -1,22 +1,36 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
fs.readFile("./dictionnaire_fr.txt", "utf8", (err, data) => {
|
fs.readFile("./dictionnaire_fr.txt", "utf8", (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("Erreur de lecture du fichier :", err);
|
console.error("Erreur de lecture du fichier :", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const words = data.split("\n").filter(word => word.trim() !== "");
|
const words = data.split("\n").filter(word => word.trim() !== "");
|
||||||
|
|
||||||
|
let wordNumber = Math.floor(Math.random() * 20 + 2);
|
||||||
|
let randomMessage = [];
|
||||||
|
|
||||||
let wordNumber = Math.floor(Math.random() * 20 + 2);
|
for (let i = 0; i < wordNumber; i++) {
|
||||||
let randomMessage = [];
|
const joiners = ["et", "ou", "alors", "mais", "donc", "car", "puis", "ensuite,", "toutefois,", "cependant,", "néanmoins,", "par conséquent", "ainsi,", "en outre", "de plus", "d'ailleurs,", "en effet", "par ailleurs"];
|
||||||
|
|
||||||
for (let i = 0; i < wordNumber; i++) {
|
const randomIndex = Math.floor(Math.random() * words.length);
|
||||||
const joiners = ["et", "ou", "alors", "mais", "donc", "car", "puis", "ensuite,", "toutefois,", "cependant,", "néanmoins,", "par conséquent", "ainsi,", "en outre", "de plus", "d'ailleurs,", "en effet", "par ailleurs"];
|
const randomWord = words[randomIndex];
|
||||||
const randomIndex = Math.floor(Math.random() * words.length);
|
const randomJoiner = joiners[Math.floor(Math.random() * joiners.length)];
|
||||||
const randomWord = words[randomIndex];
|
|
||||||
randomMessage.push(randomWord, joiners[Math.floor(Math.random() * joiners.length)]);
|
randomMessage.push(randomWord, randomJoiner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const warnings = ["ATTENTION !", "ALERTE !", "PRENEZ GARDE !", "PRUDENCE !"];
|
||||||
|
const randomWarning = warnings[Math.floor(Math.random() * warnings.length)];
|
||||||
|
|
||||||
|
// Capitalize the first word
|
||||||
|
randomMessage[0] = randomMessage[0].charAt(0).toUpperCase() + randomMessage[0].slice(1);
|
||||||
|
// Add a random warning at the beginning
|
||||||
|
randomMessage.unshift(randomWarning);
|
||||||
// Remove the last joiner
|
// Remove the last joiner
|
||||||
randomMessage.pop();
|
randomMessage.pop();
|
||||||
console.log(`Message généré : ${randomMessage.join(" ")}.`);
|
// Join the words into a single string
|
||||||
})
|
console.log(`${randomMessage.join(" ")}.`);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user