Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ref/env-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Xm0onh committed Jan 9, 2025
2 parents 461c33a + 58d5407 commit 912e337
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions auto-agents-framework/src/services/twitter/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,26 @@ const getMyRecentReplies = async (
return replies;
};
const getReplyThread = (tweet: Tweet, conversation: Tweet[]): Tweet[] => {
let tweetReply = tweet.inReplyToStatusId
? conversation.find(t => t.id === tweet.inReplyToStatusId)
: tweet;

const replyThread: Tweet[] = tweetReply ? [tweetReply] : [];
while (tweetReply && tweetReply.inReplyToStatusId) {
const nextReply = conversation.find(t => t.inReplyToStatusId === tweetReply?.id);
if (!nextReply) {
const replyThread: Tweet[] = [];
let currentTweet = tweet;

while (currentTweet) {
if (currentTweet.inReplyToStatusId) {
const parentTweet = conversation.find(t => t.id === currentTweet.inReplyToStatusId);
if (parentTweet) {
replyThread.unshift(parentTweet);
currentTweet = parentTweet;
} else {
break;
}
} else {
if (!replyThread.some(t => t.id === currentTweet.id)) {
replyThread.unshift(currentTweet);
}
break;
}
logger.info('Next Reply', { nextReply: nextReply?.id });
replyThread.push(nextReply);
tweetReply = nextReply;
}

return replyThread;
};

Expand Down Expand Up @@ -133,12 +139,12 @@ const getMyUnrepliedToMentions = async (
logger.info(`Skipping tweet ${tweet.id} (already replied)`);
continue;
}

newMentions.push(tweet);
if (!conversations.has(tweet.id!)) {
const conversation = await iterateResponse(
scraper.searchTweets(`conversation_id:${tweet.conversationId}`, 100, SearchMode.Latest),
);

const initialTweet = await scraper.getTweet(tweet.conversationId!);
if (initialTweet) {
conversation.push(initialTweet);
Expand Down

0 comments on commit 912e337

Please sign in to comment.