Skip to content

Commit 1a90509

Browse files
committed
post time set in env
1 parent 4b1caa0 commit 1a90509

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ X_SERVER_URL=
2929
XAI_API_KEY=
3030
XAI_MODEL=
3131

32+
#POST INTERVAL RANDOM MIN-MAX.
33+
POST_INTERVAL_MIN=30 #5 #Default
34+
POST_INTERVAL_MAX=90 #10 #Default
35+
36+
3237
#USE IMAGE GEN
3338
IMAGE_GEN= #TRUE
3439

packages/client-twitter/src/post.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,32 @@ 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+
33+
onReady(postImmediately: boolean = true) {
3234
const generateNewTweetLoop = () => {
33-
this.generateNewTweet();
35+
const minMinutes = parseInt(this.runtime.getSetting("POST_INTERVAL_MIN")) || 5;
36+
const maxMinutes = parseInt(this.runtime.getSetting("POST_INTERVAL_MAX")) || 15;
37+
const randomMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes;
38+
const delay = randomMinutes * 60 * 1000;
39+
3440
setTimeout(
35-
generateNewTweetLoop,
36-
(Math.floor(Math.random() * (180 - 90 + 1)) + 90) * 60 * 1000
37-
); // Random interval: min 90min/max 180min (1.5-3h), Results in min 8/max 16 posts per day
41+
() => {
42+
this.generateNewTweet();
43+
generateNewTweetLoop(); // Set up next iteration
44+
},
45+
delay
46+
);
47+
48+
console.log(`Next tweet scheduled in ${randomMinutes} minutes`);
3849
};
39-
// setTimeout(() => {
50+
51+
if (postImmediately) {
52+
this.generateNewTweet();
53+
}
4054
generateNewTweetLoop();
41-
// }, 5 * 60 * 1000); // Wait 5 minutes before starting the loop
4255
}
43-
56+
4457
constructor(runtime: IAgentRuntime) {
4558
// Initialize the client and pass an optional callback to be called when the client is ready
4659
super({

0 commit comments

Comments
 (0)