Skip to content

Commit

Permalink
pass twitterConfig as 2nd parameter to cstr, only start search once
Browse files Browse the repository at this point in the history
  • Loading branch information
odilitime committed Dec 28, 2024
1 parent ecaf554 commit d7d655f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/client-twitter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client, elizaLogger, IAgentRuntime } from "@elizaos/core";
import { ClientBase } from "./base.ts";
import { validateTwitterConfig } from "./environment.ts";
import { validateTwitterConfig, TwitterConfig } from "./environment.ts";
import { TwitterInteractionClient } from "./interactions.ts";
import { TwitterPostClient } from "./post.ts";
import { TwitterSearchClient } from "./search.ts";
Expand All @@ -10,11 +10,11 @@ class TwitterManager {
post: TwitterPostClient;
search: TwitterSearchClient;
interaction: TwitterInteractionClient;
constructor(runtime: IAgentRuntime, enableSearch: boolean) {
this.client = new ClientBase(runtime);
constructor(runtime: IAgentRuntime, twitterConfig:TwitterConfig) {
this.client = new ClientBase(runtime, twitterConfig);
this.post = new TwitterPostClient(this.client, runtime);

if (enableSearch) {
if (twitterConfig.TWITTER_SEARCH_ENABLE) {
// this searches topics from character file
elizaLogger.warn("Twitter/X client running in a mode that:");
elizaLogger.warn("1. violates consent of random users");
Expand All @@ -30,11 +30,11 @@ class TwitterManager {

export const TwitterClientInterface: Client = {
async start(runtime: IAgentRuntime) {
await validateTwitterConfig(runtime);
const twitterConfig:TwitterConfig = await validateTwitterConfig(runtime);

elizaLogger.log("Twitter client started");

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

await manager.client.init();

Expand All @@ -45,8 +45,6 @@ export const TwitterClientInterface: Client = {

await manager.interaction.start();

await manager.search?.start();

return manager;
},
async stop(_runtime: IAgentRuntime) {
Expand Down

0 comments on commit d7d655f

Please sign in to comment.