From af0b94da04cbf6c97aae6b478ea91a0eb78883dd Mon Sep 17 00:00:00 2001 From: odilitime Date: Thu, 12 Dec 2024 02:53:20 +0000 Subject: [PATCH 1/5] read TWITTER_SEARCH_ENABLE and set enableSearch on TwitterClients --- agent/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/src/index.ts b/agent/src/index.ts index 8aab1b5d38..c8b4ee9a1c 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -335,6 +335,7 @@ export async function initializeClients( } if (clientTypes.includes("twitter")) { + TwitterClientInterface.enableSearch = getSecret(character, "TWITTER_SEARCH_ENABLE"); const twitterClients = await TwitterClientInterface.start(runtime); clients.push(twitterClients); } From e7964c35019df063511d8d050a314997158342be Mon Sep 17 00:00:00 2001 From: odilitime Date: Thu, 12 Dec 2024 02:53:54 +0000 Subject: [PATCH 2/5] add enableSearch flag/property, display warning to console --- packages/client-twitter/src/index.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/client-twitter/src/index.ts b/packages/client-twitter/src/index.ts index 553d96822c..40c0eb61ed 100644 --- a/packages/client-twitter/src/index.ts +++ b/packages/client-twitter/src/index.ts @@ -10,24 +10,32 @@ class TwitterManager { post: TwitterPostClient; search: TwitterSearchClient; interaction: TwitterInteractionClient; - constructor(runtime: IAgentRuntime) { + constructor(runtime: IAgentRuntime, enableSearch:boolean) { this.client = new ClientBase(runtime); this.post = new TwitterPostClient(this.client, runtime); - //this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default - // this searches topics from character file, but kind of violates consent of random users - // burns your rate limit and can get your account banned - // use at your own risk + + if (enableSearch) { + // this searches topics from character file + elizaLogger.warn('Twitter/X client running in a mode that violates consent of random users') + elizaLogger.warn('burns your rate limit and can get your account banned') + elizaLogger.warn('use at your own risk') + this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default + } this.interaction = new TwitterInteractionClient(this.client, runtime); } } export const TwitterClientInterface: Client = { + async start(runtime: IAgentRuntime) { await validateTwitterConfig(runtime); elizaLogger.log("Twitter client started"); - const manager = new TwitterManager(runtime); + // enableSearch is just set previous to this call + // so enableSearch can change over time + // and changing it won't stop the SearchClient in the existing instance + const manager = new TwitterManager(runtime, this.enableSearch); await manager.client.init(); From 5f605107ab018c5cc2a4010cf714a0f432c810ff Mon Sep 17 00:00:00 2001 From: odilitime Date: Thu, 12 Dec 2024 06:55:46 +0000 Subject: [PATCH 3/5] isFalsish(), TWITTER_SEARCH_ENABLE accept more values that are falsish like the string FALSE --- agent/src/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/agent/src/index.ts b/agent/src/index.ts index c8b4ee9a1c..ad35595d6f 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -335,7 +335,7 @@ export async function initializeClients( } if (clientTypes.includes("twitter")) { - TwitterClientInterface.enableSearch = getSecret(character, "TWITTER_SEARCH_ENABLE"); + TwitterClientInterface.enableSearch = !isFalsish(getSecret(character, "TWITTER_SEARCH_ENABLE")); const twitterClients = await TwitterClientInterface.start(runtime); clients.push(twitterClients); } @@ -359,6 +359,22 @@ export async function initializeClients( return clients; } +function isFalsish(input: any): boolean { + // If the input is exactly NaN, return true + if (Number.isNaN(input)) { + return true; + } + + // Convert input to a string if it's not null or undefined + const value = input == null ? '' : String(input); + + // List of common falsish string representations + const falsishValues = ['false', '0', 'no', 'n', 'off', 'null', 'undefined', '']; + + // Check if the value (trimmed and lowercased) is in the falsish list + return falsishValues.includes(value.trim().toLowerCase()); +} + function getSecret(character: Character, secret: string) { return character.settings.secrets?.[secret] || process.env[secret]; } From c5b5dd9ee57fce689b8e7958ddbd95814d447441 Mon Sep 17 00:00:00 2001 From: odilitime Date: Thu, 12 Dec 2024 07:01:35 +0000 Subject: [PATCH 4/5] add TWITTER_SEARCH_ENABLE --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index 2f4957a2b5..81e4fea0c4 100644 --- a/.env.example +++ b/.env.example @@ -53,6 +53,7 @@ TWITTER_EMAIL= # Account email TWITTER_2FA_SECRET= TWITTER_COOKIES= # Account cookies TWITTER_POLL_INTERVAL=120 # How often (in seconds) the bot should check for interactions +TWITTER_SEARCH_ENABLE=FALSE # Enable timeline search, WARNING this greatly increases your chance of getting banned X_SERVER_URL= XAI_API_KEY= XAI_MODEL= From ddc08e08f254ca8c4d98013831665ff9d072217b Mon Sep 17 00:00:00 2001 From: odilitime Date: Thu, 12 Dec 2024 07:02:01 +0000 Subject: [PATCH 5/5] update warning message to be more coherent --- packages/client-twitter/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/client-twitter/src/index.ts b/packages/client-twitter/src/index.ts index 40c0eb61ed..b973b84eae 100644 --- a/packages/client-twitter/src/index.ts +++ b/packages/client-twitter/src/index.ts @@ -16,8 +16,10 @@ class TwitterManager { if (enableSearch) { // this searches topics from character file - elizaLogger.warn('Twitter/X client running in a mode that violates consent of random users') - elizaLogger.warn('burns your rate limit and can get your account banned') + elizaLogger.warn('Twitter/X client running in a mode that:') + elizaLogger.warn('1. violates consent of random users') + elizaLogger.warn('2. burns your rate limit') + elizaLogger.warn('3. can get your account banned') elizaLogger.warn('use at your own risk') this.search = new TwitterSearchClient(this.client, runtime); // don't start the search client by default }