Skip to content

Commit 5946e60

Browse files
authored
Set the post min max time
1 parent 79637da commit 5946e60

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

packages/client-twitter/src/post.ts

+20-7
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,31 @@ Write a single sentence post that is {{adjective}} about {{topic}} (without ment
2828
Your response should not contain any questions. Brief, concise statements only. No emojis. Use \\n\\n (double spaces) between statements.`;
2929

3030
export class TwitterPostClient extends ClientBase {
31-
onReady() {
31+
32+
onReady(postImmediately: boolean = true) {
3233
const generateNewTweetLoop = () => {
33-
this.generateNewTweet();
34+
const minMinutes = this.runtime.getSetting("POST_INTERVAL_MIN"),;
35+
const maxMinutes = this.runtime.getSetting("POST_INTERVAL_MAX"),;
36+
const randomMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes;
37+
const delay = randomMinutes * 60 * 1000;
38+
3439
setTimeout(
35-
generateNewTweetLoop,
36-
(Math.floor(Math.random() * (20 - 2 + 1)) + 2) * 60 * 1000
37-
); // Random interval between 4-8 hours
40+
() => {
41+
this.generateNewTweet();
42+
generateNewTweetLoop(); // Set up next iteration
43+
},
44+
delay
45+
);
46+
47+
console.log(`Next tweet scheduled in ${randomMinutes} minutes`);
3848
};
39-
// setTimeout(() => {
49+
50+
if (postImmediately) {
51+
this.generateNewTweet();
52+
}
4053
generateNewTweetLoop();
41-
// }, 5 * 60 * 1000); // Wait 5 minutes before starting the loop
4254
}
55+
4356

4457
constructor(runtime: IAgentRuntime) {
4558
// Initialize the client and pass an optional callback to be called when the client is ready

0 commit comments

Comments
 (0)