Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

post time set in env #368

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 21 additions & 8 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading