Skip to content

Commit

Permalink
Merge pull request #1244 from renlulu/feat/env-twitter-retry
Browse files Browse the repository at this point in the history
feat: make twitter login retry times as env
  • Loading branch information
monilpat authored Dec 19, 2024
2 parents 86005ad + 370ea70 commit 1edb372
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ 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
TWITTER_TARGET_USERS= # Comma separated list of Twitter user names to interact with
TWITTER_RETRY_LIMIT= # Maximum retry attempts for Twitter login

X_SERVER_URL=
XAI_API_KEY=
Expand Down
4 changes: 2 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {

async function startAgent(
character: Character,
directClient
directClient: DirectClient
): Promise<AgentRuntime> {
let db: IDatabaseAdapter & IDatabaseCacheAdapter;
try {
Expand Down Expand Up @@ -653,7 +653,7 @@ const startAgents = async () => {
}

// upload some agent functionality into directClient
directClient.startAgent = async (character) => {
directClient.startAgent = async (character: Character) => {
// wrap it so we don't have to inject directClient later
return startAgent(character, directClient);
};
Expand Down
5 changes: 4 additions & 1 deletion packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export class ClientBase extends EventEmitter {
const username = this.runtime.getSetting("TWITTER_USERNAME");
const password = this.runtime.getSetting("TWITTER_PASSWORD");
const email = this.runtime.getSetting("TWITTER_EMAIL");
let retries = parseInt(
this.runtime.getSetting("TWITTER_RETRY_LIMIT") || "5",
10
);
const twitter2faSecret =
this.runtime.getSetting("TWITTER_2FA_SECRET") || undefined;
const cookies = this.runtime.getSetting("TWITTER_COOKIES");
Expand All @@ -180,7 +184,6 @@ export class ClientBase extends EventEmitter {
}

elizaLogger.log("Waiting for Twitter login");
let retries = 5; // Optional: Set a retry limit
while (retries > 0) {
const cookies = await this.twitterClient.getCookies();
if ((await this.twitterClient.isLoggedIn()) && !!cookies) {
Expand Down

0 comments on commit 1edb372

Please sign in to comment.