Skip to content

Commit

Permalink
Merge pull request #1433 from nulLeeKH/main
Browse files Browse the repository at this point in the history
fix: Make search feature in twitter client works
  • Loading branch information
twilwa authored Dec 25, 2024
2 parents 3edac48 + 09f0053 commit 49aa5d9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ concatenated-output.ts
embedding-cache.json
packages/plugin-buttplug/intiface-engine

.idea
.DS_Store

dist/
Expand Down
29 changes: 0 additions & 29 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,8 @@ export async function initializeClients(

if (clientTypes.includes(Clients.TWITTER)) {
const twitterClient = await TwitterClientInterface.start(runtime);

if (twitterClient) {
clients.twitter = twitterClient;
(twitterClient as any).enableSearch = !isFalsish(
getSecret(character, "TWITTER_SEARCH_ENABLE")
);
}
}

Expand Down Expand Up @@ -434,31 +430,6 @@ 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];
}
Expand Down
5 changes: 4 additions & 1 deletion packages/client-twitter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ export const TwitterClientInterface: Client = {

elizaLogger.log("Twitter client started");

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

await manager.client.init();

await manager.post.start();

if (manager.search)
await manager.search.start();

await manager.interaction.start();

await manager.search?.start();
Expand Down
8 changes: 5 additions & 3 deletions packages/client-twitter/src/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SearchMode } from "agent-twitter-client";
import { composeContext } from "@elizaos/core";
import {composeContext, elizaLogger} from "@elizaos/core";
import { generateMessageResponse, generateText } from "@elizaos/core";
import { messageCompletionFooter } from "@elizaos/core";
import {
Expand Down Expand Up @@ -59,10 +59,12 @@ export class TwitterSearchClient {
}

private engageWithSearchTermsLoop() {
this.engageWithSearchTerms();
this.engageWithSearchTerms().then();
const randomMinutes = (Math.floor(Math.random() * (120 - 60 + 1)) + 60);
elizaLogger.log(`Next twitter search scheduled in ${randomMinutes} minutes`);
setTimeout(
() => this.engageWithSearchTermsLoop(),
(Math.floor(Math.random() * (120 - 60 + 1)) + 60) * 60 * 1000
randomMinutes * 60 * 1000
);
}

Expand Down

0 comments on commit 49aa5d9

Please sign in to comment.