Skip to content

Commit

Permalink
fix(client-twitter): clean up mention deduplication (elizaOS#2185)
Browse files Browse the repository at this point in the history
Co-authored-by: Odilitime <janesmith@airmail.cc>
  • Loading branch information
nhodges and odilitime authored Jan 12, 2025
1 parent feb9a53 commit f37275e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/client-twitter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,19 @@ function deduplicateMentions(paragraph: string) {
}

// Extract mentions from the match groups
let mentions = matches.slice(1).filter(Boolean) as string[];
let mentions = matches.slice(0, 1)[0].trim().split(' ')

// Deduplicate mentions
mentions = [...new Set(mentions)];

// Reconstruct the string with deduplicated mentions
const uniqueMentionsString = `@${mentions.join(' ')}`;
const uniqueMentionsString = mentions.join(' ');

// Find where the mentions end in the original string
const endOfMentions = paragraph.indexOf(matches[0]) + matches[0].length;

// Construct the result by combining unique mentions with the rest of the string
return uniqueMentionsString + paragraph.slice(endOfMentions);
return uniqueMentionsString + ' ' + paragraph.slice(endOfMentions);
}

function restoreUrls(
Expand Down Expand Up @@ -454,4 +454,4 @@ function splitParagraph(paragraph: string, maxLength: number): string[] {
const restoredChunks = restoreUrls(splittedChunks, placeholderMap);

return restoredChunks;
}
}

0 comments on commit f37275e

Please sign in to comment.