Skip to content

Commit

Permalink
Merge pull request #368 from o-on-x/main
Browse files Browse the repository at this point in the history
post time set in env
o-on-x authored Nov 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 4b1caa0 + 1a90509 commit 7bc8edc
Showing 2 changed files with 26 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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

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

0 comments on commit 7bc8edc

Please sign in to comment.