File tree 1 file changed +20
-7
lines changed
1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -28,18 +28,31 @@ Write a single sentence post that is {{adjective}} about {{topic}} (without ment
28
28
Your response should not contain any questions. Brief, concise statements only. No emojis. Use \\n\\n (double spaces) between statements.` ;
29
29
30
30
export class TwitterPostClient extends ClientBase {
31
- onReady ( ) {
31
+
32
+ onReady ( postImmediately : boolean = true ) {
32
33
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
+
34
39
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` ) ;
38
48
} ;
39
- // setTimeout(() => {
49
+
50
+ if ( postImmediately ) {
51
+ this . generateNewTweet ( ) ;
52
+ }
40
53
generateNewTweetLoop ( ) ;
41
- // }, 5 * 60 * 1000); // Wait 5 minutes before starting the loop
42
54
}
55
+
43
56
44
57
constructor ( runtime : IAgentRuntime ) {
45
58
// Initialize the client and pass an optional callback to be called when the client is ready
You can’t perform that action at this time.
0 commit comments