diff --git a/.env.example b/.env.example index 6407ffd8a3e..5bfbb9295b3 100644 --- a/.env.example +++ b/.env.example @@ -29,6 +29,11 @@ X_SERVER_URL= XAI_API_KEY= XAI_MODEL= +#POST INTERVAL RANDOM MIN-MAX. +POST_INTERVAL_MIN=30 #5 #Default +POST_INTERVAL_MAX=90 #10 #Default + + #USE IMAGE GEN IMAGE_GEN= #TRUE diff --git a/packages/client-twitter/src/post.ts b/packages/client-twitter/src/post.ts index a999dded379..8a759673f76 100644 --- a/packages/client-twitter/src/post.ts +++ b/packages/client-twitter/src/post.ts @@ -28,19 +28,32 @@ Write a single sentence post that is {{adjective}} about {{topic}} (without ment Your response should not contain any questions. Brief, concise statements only. No emojis. Use \\n\\n (double spaces) between statements.`; export class TwitterPostClient extends ClientBase { - onReady() { + + + onReady(postImmediately: boolean = true) { const generateNewTweetLoop = () => { - this.generateNewTweet(); + const minMinutes = parseInt(this.runtime.getSetting("POST_INTERVAL_MIN")) || 5; + const maxMinutes = parseInt(this.runtime.getSetting("POST_INTERVAL_MAX")) || 15; + const randomMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes; + const delay = randomMinutes * 60 * 1000; + setTimeout( - generateNewTweetLoop, - (Math.floor(Math.random() * (180 - 90 + 1)) + 90) * 60 * 1000 - ); // Random interval: min 90min/max 180min (1.5-3h), Results in min 8/max 16 posts per day + () => { + this.generateNewTweet(); + generateNewTweetLoop(); // Set up next iteration + }, + delay + ); + + console.log(`Next tweet scheduled in ${randomMinutes} minutes`); }; - // setTimeout(() => { + + if (postImmediately) { + this.generateNewTweet(); + } generateNewTweetLoop(); - // }, 5 * 60 * 1000); // Wait 5 minutes before starting the loop } - + constructor(runtime: IAgentRuntime) { // Initialize the client and pass an optional callback to be called when the client is ready super({