This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

Update wolf-noise-generator.ts

added random chance for the function to occasionally generate posts with only a few words (between 1-5)

+80 -50
+80 -50
wolf-noise-generator.ts
··· 10 10 howl: string[]; 11 11 playful: string[]; 12 12 scared: string[]; 13 - punctuation: { [category: string]: string[]; }; // Nested object for category-specific punctuation 13 + punctuation: { [category: string]: string[] }; // Nested object for category-specific punctuation 14 14 } { 15 15 try { 16 16 const data = fs.readFileSync("./wolf-noises.json", "utf-8"); ··· 22 22 } 23 23 24 24 export function generateWolfNoiseString(): string { 25 - const wolfNoises = getWolfNoises(); // Read JSON data 26 - const categoryProbabilities = { 27 - howl: 0.4, // 40% chance 28 - playful: 0.3, // 30% chance 29 - scared: 0.3 // 30% chance 30 - }; 31 - 32 - const random = Math.random(); 33 - let category; 34 - 35 - // Determine the category based on probabilities 36 - if (random < categoryProbabilities.howl) { 37 - category = "howl"; 38 - } else if (random < categoryProbabilities.howl + categoryProbabilities.playful) { 39 - category = "playful"; 25 + const wolfNoises = getWolfNoises(); // Read JSON data 26 + const categoryProbabilities = { 27 + howl: 0.4, // 40% chance 28 + playful: 0.3, // 30% chance 29 + scared: 0.3, // 30% chance 30 + }; 31 + 32 + const random = Math.random(); 33 + let category; 34 + 35 + // Determine the category based on probabilities 36 + if (random < categoryProbabilities.howl) { 37 + category = "howl"; 38 + } else if ( 39 + random < 40 + categoryProbabilities.howl + categoryProbabilities.playful 41 + ) { 42 + category = "playful"; 43 + } else { 44 + category = "scared"; 45 + } 46 + 47 + const randomWords = wolfNoises[category]; // Get words for the selected category 48 + 49 + let result = ""; 50 + let currentSentenceLength = 0; 51 + 52 + // Determine whether to generate a shorter post, longer post, or very short post 53 + const shorterPostProbability = 0.7; // 70% chance of generating a shorter or very short post 54 + const generateShorterOrVeryShortPost = Math.random() < shorterPostProbability; 55 + let maxLength; 56 + 57 + if (generateShorterOrVeryShortPost) { 58 + // Determine whether to generate a very short post (1-5 words) or a shorter post (up to 140 or 280 characters) 59 + const veryShortPostProbability = 0.3; // 30% chance of generating a very short post 60 + const generateVeryShortPost = Math.random() < veryShortPostProbability; 61 + 62 + if (generateVeryShortPost) { 63 + // Generate a very short post (1-5 words) 64 + const wordCount = getRandomInt(1, 5); 65 + maxLength = wordCount * 10; // Assuming an average word length of 10 characters 40 66 } else { 41 - category = "scared"; 67 + // Generate a shorter post (up to 140 or 280 characters) 68 + maxLength = getRandomInt(70, 140); // For shorter post 69 + // maxLength = getRandomInt(140, 280); // For longer post 42 70 } 43 - 44 - const randomWords = wolfNoises[category]; // Get words for the selected category 45 - 46 - let result = ""; 47 - let currentSentenceLength = 0; 48 - 49 - const maxLength = 280; // Set maximum length for the generated string 50 - 51 - while (result.length < maxLength) { 52 - const randomWord = randomWords[getRandomInt(0, randomWords.length - 1)]; 53 - const wordLength = randomWord.length; 54 - 55 - // Check if adding the word exceeds the maximum length 56 - if (result.length + wordLength <= maxLength) { 57 - // Add a space if it's not the first word and result is not empty 58 - if (result.length > 0) { 59 - result += " "; 60 - } 61 - result += randomWord; 62 - currentSentenceLength += wordLength; 63 - } else { 64 - // Break the loop if adding the word would exceed the maximum length 65 - break; 71 + } else { 72 + // Generate a longer post (up to 280 characters) 73 + maxLength = 280; 74 + } 75 + 76 + while (result.length < maxLength) { 77 + const randomWord = randomWords[getRandomInt(0, randomWords.length - 1)]; 78 + const wordLength = randomWord.length; 79 + 80 + // Check if adding the word exceeds the maximum length 81 + if (result.length + wordLength <= maxLength) { 82 + // Add a space if it's not the first word and result is not empty 83 + if (result.length > 0) { 84 + result += " "; 66 85 } 67 - } 68 - 69 - // Optionally add punctuation based on the selected category 70 - if (wolfNoises.punctuation && wolfNoises.punctuation[category] && wolfNoises.punctuation[category].length > 0) { 71 - const punctuationLength = wolfNoises.punctuation[category].length; 72 - const randomPunctuation = wolfNoises.punctuation[category][getRandomInt(0, punctuationLength - 1)]; 73 - result += randomPunctuation; 86 + result += randomWord; 87 + currentSentenceLength += wordLength; 88 + } else { 89 + // Break the loop if adding the word would exceed the maximum length 90 + break; 74 91 } 75 - 76 - return result.trim(); // Remove any leading/trailing whitespace 77 - } 92 + } 93 + 94 + // Optionally add punctuation based on the selected category 95 + if ( 96 + wolfNoises.punctuation && 97 + wolfNoises.punctuation[category] && 98 + wolfNoises.punctuation[category].length > 0 99 + ) { 100 + const punctuationLength = wolfNoises.punctuation[category].length; 101 + const randomPunctuation = 102 + wolfNoises.punctuation[category][getRandomInt(0, punctuationLength - 1)]; 103 + result += randomPunctuation; 104 + } 105 + 106 + return result.trim(); // Remove any leading/trailing whitespace 107 + }