@@ -62,15 +62,18 @@ const MAX_TWEET_LENGTH = 240;
62
62
/**
63
63
* Truncate text to fit within the Twitter character limit, ensuring it ends at a complete sentence.
64
64
*/
65
- function truncateToCompleteSentence ( text : string ) : string {
66
- if ( text . length <= MAX_TWEET_LENGTH ) {
65
+ function truncateToCompleteSentence (
66
+ text : string ,
67
+ maxTweetLength : number
68
+ ) : string {
69
+ if ( text . length <= maxTweetLength ) {
67
70
return text ;
68
71
}
69
72
70
73
// Attempt to truncate at the last period within the limit
71
74
const truncatedAtPeriod = text . slice (
72
75
0 ,
73
- text . lastIndexOf ( "." , MAX_TWEET_LENGTH ) + 1
76
+ text . lastIndexOf ( "." , maxTweetLength ) + 1
74
77
) ;
75
78
if ( truncatedAtPeriod . trim ( ) . length > 0 ) {
76
79
return truncatedAtPeriod . trim ( ) ;
@@ -79,16 +82,17 @@ function truncateToCompleteSentence(text: string): string {
79
82
// If no period is found, truncate to the nearest whitespace
80
83
const truncatedAtSpace = text . slice (
81
84
0 ,
82
- text . lastIndexOf ( " " , MAX_TWEET_LENGTH )
85
+ text . lastIndexOf ( " " , maxTweetLength )
83
86
) ;
84
87
if ( truncatedAtSpace . trim ( ) . length > 0 ) {
85
88
return truncatedAtSpace . trim ( ) + "..." ;
86
89
}
87
90
88
91
// Fallback: Hard truncate and add ellipsis
89
- return text . slice ( 0 , MAX_TWEET_LENGTH - 3 ) . trim ( ) + "..." ;
92
+ return text . slice ( 0 , maxTweetLength - 3 ) . trim ( ) + "..." ;
90
93
}
91
94
95
+
92
96
export class TwitterPostClient {
93
97
client : ClientBase ;
94
98
runtime : IAgentRuntime ;
@@ -113,9 +117,9 @@ export class TwitterPostClient {
113
117
114
118
const lastPostTimestamp = lastPost ?. timestamp ?? 0 ;
115
119
const minMinutes =
116
- parseInt ( this . runtime . getSetting ( "POST_INTERVAL_MIN" ) ) || 1 ;
120
+ parseInt ( this . runtime . getSetting ( "POST_INTERVAL_MIN" ) ) || 90 ;
117
121
const maxMinutes =
118
- parseInt ( this . runtime . getSetting ( "POST_INTERVAL_MAX" ) ) || 2 ;
122
+ parseInt ( this . runtime . getSetting ( "POST_INTERVAL_MAX" ) ) || 180 ;
119
123
const randomMinutes =
120
124
Math . floor ( Math . random ( ) * ( maxMinutes - minMinutes + 1 ) ) +
121
125
minMinutes ;
@@ -227,7 +231,6 @@ export class TwitterPostClient {
227
231
} ) ;
228
232
229
233
elizaLogger . debug ( "generate post prompt:\n" + context ) ;
230
- console . log ( "generate post prompt:\n" + context ) ;
231
234
232
235
const newTweetContent = await generateText ( {
233
236
runtime : this . runtime ,
@@ -264,7 +267,7 @@ export class TwitterPostClient {
264
267
}
265
268
266
269
// Use the helper function to truncate to complete sentence
267
- const content = truncateToCompleteSentence ( cleanedContent ) ;
270
+ const content = truncateToCompleteSentence ( cleanedContent , MAX_TWEET_LENGTH ) ;
268
271
269
272
const removeQuotes = ( str : string ) =>
270
273
str . replace ( / ^ [ ' " ] ( .* ) [ ' " ] $ / , "$1" ) ;
0 commit comments