···1010 howl: string[];
1111 playful: string[];
1212 scared: string[];
1313- punctuation: { [category: string]: string[]; }; // Nested object for category-specific punctuation
1313+ punctuation: { [category: string]: string[] }; // Nested object for category-specific punctuation
1414} {
1515 try {
1616 const data = fs.readFileSync("./wolf-noises.json", "utf-8");
···2222}
23232424export function generateWolfNoiseString(): string {
2525- const wolfNoises = getWolfNoises(); // Read JSON data
2626- const categoryProbabilities = {
2727- howl: 0.4, // 40% chance
2828- playful: 0.3, // 30% chance
2929- scared: 0.3 // 30% chance
3030- };
3131-3232- const random = Math.random();
3333- let category;
3434-3535- // Determine the category based on probabilities
3636- if (random < categoryProbabilities.howl) {
3737- category = "howl";
3838- } else if (random < categoryProbabilities.howl + categoryProbabilities.playful) {
3939- category = "playful";
2525+ const wolfNoises = getWolfNoises(); // Read JSON data
2626+ const categoryProbabilities = {
2727+ howl: 0.4, // 40% chance
2828+ playful: 0.3, // 30% chance
2929+ scared: 0.3, // 30% chance
3030+ };
3131+3232+ const random = Math.random();
3333+ let category;
3434+3535+ // Determine the category based on probabilities
3636+ if (random < categoryProbabilities.howl) {
3737+ category = "howl";
3838+ } else if (
3939+ random <
4040+ categoryProbabilities.howl + categoryProbabilities.playful
4141+ ) {
4242+ category = "playful";
4343+ } else {
4444+ category = "scared";
4545+ }
4646+4747+ const randomWords = wolfNoises[category]; // Get words for the selected category
4848+4949+ let result = "";
5050+ let currentSentenceLength = 0;
5151+5252+ // Determine whether to generate a shorter post, longer post, or very short post
5353+ const shorterPostProbability = 0.7; // 70% chance of generating a shorter or very short post
5454+ const generateShorterOrVeryShortPost = Math.random() < shorterPostProbability;
5555+ let maxLength;
5656+5757+ if (generateShorterOrVeryShortPost) {
5858+ // Determine whether to generate a very short post (1-5 words) or a shorter post (up to 140 or 280 characters)
5959+ const veryShortPostProbability = 0.3; // 30% chance of generating a very short post
6060+ const generateVeryShortPost = Math.random() < veryShortPostProbability;
6161+6262+ if (generateVeryShortPost) {
6363+ // Generate a very short post (1-5 words)
6464+ const wordCount = getRandomInt(1, 5);
6565+ maxLength = wordCount * 10; // Assuming an average word length of 10 characters
4066 } else {
4141- category = "scared";
6767+ // Generate a shorter post (up to 140 or 280 characters)
6868+ maxLength = getRandomInt(70, 140); // For shorter post
6969+ // maxLength = getRandomInt(140, 280); // For longer post
4270 }
4343-4444- const randomWords = wolfNoises[category]; // Get words for the selected category
4545-4646- let result = "";
4747- let currentSentenceLength = 0;
4848-4949- const maxLength = 280; // Set maximum length for the generated string
5050-5151- while (result.length < maxLength) {
5252- const randomWord = randomWords[getRandomInt(0, randomWords.length - 1)];
5353- const wordLength = randomWord.length;
5454-5555- // Check if adding the word exceeds the maximum length
5656- if (result.length + wordLength <= maxLength) {
5757- // Add a space if it's not the first word and result is not empty
5858- if (result.length > 0) {
5959- result += " ";
6060- }
6161- result += randomWord;
6262- currentSentenceLength += wordLength;
6363- } else {
6464- // Break the loop if adding the word would exceed the maximum length
6565- break;
7171+ } else {
7272+ // Generate a longer post (up to 280 characters)
7373+ maxLength = 280;
7474+ }
7575+7676+ while (result.length < maxLength) {
7777+ const randomWord = randomWords[getRandomInt(0, randomWords.length - 1)];
7878+ const wordLength = randomWord.length;
7979+8080+ // Check if adding the word exceeds the maximum length
8181+ if (result.length + wordLength <= maxLength) {
8282+ // Add a space if it's not the first word and result is not empty
8383+ if (result.length > 0) {
8484+ result += " ";
6685 }
6767- }
6868-6969- // Optionally add punctuation based on the selected category
7070- if (wolfNoises.punctuation && wolfNoises.punctuation[category] && wolfNoises.punctuation[category].length > 0) {
7171- const punctuationLength = wolfNoises.punctuation[category].length;
7272- const randomPunctuation = wolfNoises.punctuation[category][getRandomInt(0, punctuationLength - 1)];
7373- result += randomPunctuation;
8686+ result += randomWord;
8787+ currentSentenceLength += wordLength;
8888+ } else {
8989+ // Break the loop if adding the word would exceed the maximum length
9090+ break;
7491 }
7575-7676- return result.trim(); // Remove any leading/trailing whitespace
7777- } 9292+ }
9393+9494+ // Optionally add punctuation based on the selected category
9595+ if (
9696+ wolfNoises.punctuation &&
9797+ wolfNoises.punctuation[category] &&
9898+ wolfNoises.punctuation[category].length > 0
9999+ ) {
100100+ const punctuationLength = wolfNoises.punctuation[category].length;
101101+ const randomPunctuation =
102102+ wolfNoises.punctuation[category][getRandomInt(0, punctuationLength - 1)];
103103+ result += randomPunctuation;
104104+ }
105105+106106+ return result.trim(); // Remove any leading/trailing whitespace
107107+}