Skip to content

Commit 49aa5d9

Browse files
authored
Merge pull request elizaOS#1433 from nulLeeKH/main
fix: Make search feature in twitter client works
2 parents 3edac48 + 09f0053 commit 49aa5d9

File tree

4 files changed

+10
-33
lines changed

4 files changed

+10
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ concatenated-output.ts
99
embedding-cache.json
1010
packages/plugin-buttplug/intiface-engine
1111

12+
.idea
1213
.DS_Store
1314

1415
dist/

agent/src/index.ts

-29
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,8 @@ export async function initializeClients(
387387

388388
if (clientTypes.includes(Clients.TWITTER)) {
389389
const twitterClient = await TwitterClientInterface.start(runtime);
390-
391390
if (twitterClient) {
392391
clients.twitter = twitterClient;
393-
(twitterClient as any).enableSearch = !isFalsish(
394-
getSecret(character, "TWITTER_SEARCH_ENABLE")
395-
);
396392
}
397393
}
398394

@@ -434,31 +430,6 @@ export async function initializeClients(
434430
return clients;
435431
}
436432

437-
function isFalsish(input: any): boolean {
438-
// If the input is exactly NaN, return true
439-
if (Number.isNaN(input)) {
440-
return true;
441-
}
442-
443-
// Convert input to a string if it's not null or undefined
444-
const value = input == null ? "" : String(input);
445-
446-
// List of common falsish string representations
447-
const falsishValues = [
448-
"false",
449-
"0",
450-
"no",
451-
"n",
452-
"off",
453-
"null",
454-
"undefined",
455-
"",
456-
];
457-
458-
// Check if the value (trimmed and lowercased) is in the falsish list
459-
return falsishValues.includes(value.trim().toLowerCase());
460-
}
461-
462433
function getSecret(character: Character, secret: string) {
463434
return character.settings?.secrets?.[secret] || process.env[secret];
464435
}

packages/client-twitter/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ export const TwitterClientInterface: Client = {
3434

3535
elizaLogger.log("Twitter client started");
3636

37-
const manager = new TwitterManager(runtime, this.enableSearch);
37+
const manager = new TwitterManager(runtime, runtime.getSetting("TWITTER_SEARCH_ENABLE").toLowerCase() === "true");
3838

3939
await manager.client.init();
4040

4141
await manager.post.start();
4242

43+
if (manager.search)
44+
await manager.search.start();
45+
4346
await manager.interaction.start();
4447

4548
await manager.search?.start();

packages/client-twitter/src/search.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SearchMode } from "agent-twitter-client";
2-
import { composeContext } from "@elizaos/core";
2+
import {composeContext, elizaLogger} from "@elizaos/core";
33
import { generateMessageResponse, generateText } from "@elizaos/core";
44
import { messageCompletionFooter } from "@elizaos/core";
55
import {
@@ -59,10 +59,12 @@ export class TwitterSearchClient {
5959
}
6060

6161
private engageWithSearchTermsLoop() {
62-
this.engageWithSearchTerms();
62+
this.engageWithSearchTerms().then();
63+
const randomMinutes = (Math.floor(Math.random() * (120 - 60 + 1)) + 60);
64+
elizaLogger.log(`Next twitter search scheduled in ${randomMinutes} minutes`);
6365
setTimeout(
6466
() => this.engageWithSearchTermsLoop(),
65-
(Math.floor(Math.random() * (120 - 60 + 1)) + 60) * 60 * 1000
67+
randomMinutes * 60 * 1000
6668
);
6769
}
6870

0 commit comments

Comments
 (0)