Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Add configuration for enabling/disabling Twitter post generation #3219

Merged
merged 3 commits into from
Feb 4, 2025
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ TWITTER_SEARCH_ENABLE=FALSE # Enable timeline search, WARNING this greatly incre
TWITTER_TARGET_USERS= # Comma separated list of Twitter user names to interact with
TWITTER_RETRY_LIMIT= # Maximum retry attempts for Twitter login
TWITTER_SPACES_ENABLE=false # Enable or disable Twitter Spaces logic
ENABLE_TWITTER_POST_GENERATION=true # Set to true to enable automatic tweet generation. If false, the bot will not generate or post tweets.
# Post Interval Settings (in minutes)
POST_INTERVAL_MIN= # Default: 90
POST_INTERVAL_MAX= # Default: 180
Expand Down
9 changes: 9 additions & 0 deletions packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const twitterEnvSchema = z.object({
.optional()
.default(''),
*/
ENABLE_TWITTER_POST_GENERATION: z.boolean(),
POST_INTERVAL_MIN: z.number().int(),
POST_INTERVAL_MAX: z.number().int(),
ENABLE_ACTION_PROCESSING: z.boolean(),
Expand Down Expand Up @@ -173,6 +174,14 @@ export async function validateTwitterConfig(
process.env.TWITTER_TARGET_USERS
),

// bool
ENABLE_TWITTER_POST_GENERATION:
parseBooleanFromText(
runtime.getSetting("ENABLE_TWITTER_POST_GENERATION") ||
process.env.ENABLE_TWITTER_POST_GENERATION
) ?? true,


// int in minutes
POST_INTERVAL_MIN: safeParseInt(
runtime.getSetting("POST_INTERVAL_MIN") ||
Expand Down
11 changes: 9 additions & 2 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export class TwitterPostClient {
elizaLogger.log(
`- Dry Run Mode: ${this.isDryRun ? "enabled" : "disabled"}`
);

elizaLogger.log(
`- Enable Post: ${this.client.twitterConfig.ENABLE_TWITTER_POST_GENERATION ? "enabled" : "disabled"}`
);

elizaLogger.log(
`- Post Interval: ${this.client.twitterConfig.POST_INTERVAL_MIN}-${this.client.twitterConfig.POST_INTERVAL_MAX} minutes`
);
Expand Down Expand Up @@ -287,8 +292,10 @@ export class TwitterPostClient {
await this.generateNewTweet();
}

generateNewTweetLoop();
elizaLogger.log("Tweet generation loop started");
if (this.client.twitterConfig.ENABLE_TWITTER_POST_GENERATION) {
generateNewTweetLoop();
elizaLogger.log("Tweet generation loop started");
}

if (this.client.twitterConfig.ENABLE_ACTION_PROCESSING) {
processActionsLoop().catch((error) => {
Expand Down
Loading