@elizaos/plugin-twitter 1.2.7 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7443,9 +7443,11 @@ import {
7443
7443
  var TwitterDiscoveryClient = class {
7444
7444
  constructor(client, runtime, state) {
7445
7445
  this.isRunning = false;
7446
+ this.lastDiscoveryTime = 0;
7446
7447
  this.client = client;
7447
7448
  this.twitterClient = client.twitterClient;
7448
7449
  this.runtime = runtime;
7450
+ this.state = state;
7449
7451
  const dryRunSetting = state?.TWITTER_DRY_RUN ?? getSetting(this.runtime, "TWITTER_DRY_RUN") ?? process.env.TWITTER_DRY_RUN;
7450
7452
  this.isDryRun = dryRunSetting === true || dryRunSetting === "true" || typeof dryRunSetting === "string" && dryRunSetting.toLowerCase() === "true";
7451
7453
  this.config = this.buildDiscoveryConfig();
@@ -7457,6 +7459,17 @@ var TwitterDiscoveryClient = class {
7457
7459
  maxEngagementsPerCycle: this.config.maxEngagementsPerCycle
7458
7460
  });
7459
7461
  }
7462
+ /**
7463
+ * Sanitizes a topic for use in Twitter search queries
7464
+ * - Removes common stop words that might be interpreted as operators
7465
+ * - Handles special characters
7466
+ * - Simplifies complex phrases
7467
+ */
7468
+ sanitizeTopic(topic) {
7469
+ let sanitized = topic.replace(/\band\b/gi, " ").replace(/\bor\b/gi, " ").replace(/\bnot\b/gi, " ").trim();
7470
+ sanitized = sanitized.replace(/\s+/g, " ");
7471
+ return sanitized.includes(" ") ? `"${sanitized}"` : sanitized;
7472
+ }
7460
7473
  buildDiscoveryConfig() {
7461
7474
  const character = this.runtime?.character;
7462
7475
  const defaultTopics = [
@@ -7582,7 +7595,8 @@ var TwitterDiscoveryClient = class {
7582
7595
  const accounts = /* @__PURE__ */ new Map();
7583
7596
  for (const topic of this.config.topics.slice(0, 5)) {
7584
7597
  try {
7585
- const popularQuery = `${topic} -is:retweet -is:reply min_faves:10 lang:en`;
7598
+ const searchTopic = this.sanitizeTopic(topic);
7599
+ const popularQuery = `${searchTopic} -is:retweet -is:reply lang:en`;
7586
7600
  logger6.debug(`Searching popular tweets for topic: ${topic}`);
7587
7601
  const popularResults = await this.twitterClient.fetchSearchTweets(
7588
7602
  popularQuery,
@@ -7590,10 +7604,11 @@ var TwitterDiscoveryClient = class {
7590
7604
  0 /* Top */
7591
7605
  );
7592
7606
  for (const tweet of popularResults.tweets) {
7607
+ if ((tweet.likes || 0) < 10) continue;
7593
7608
  const scored = this.scoreTweet(tweet, "topic");
7594
7609
  tweets.push(scored);
7595
7610
  }
7596
- const verifiedQuery = `${topic} -is:retweet lang:en filter:verified`;
7611
+ const verifiedQuery = `${searchTopic} -is:retweet lang:en is:verified`;
7597
7612
  logger6.debug(`Searching verified accounts for topic: ${topic}`);
7598
7613
  const verifiedResults = await this.twitterClient.fetchSearchTweets(
7599
7614
  verifiedQuery,
@@ -7626,9 +7641,9 @@ var TwitterDiscoveryClient = class {
7626
7641
  logger6.debug("Discovering from conversation threads...");
7627
7642
  const tweets = [];
7628
7643
  const accounts = /* @__PURE__ */ new Map();
7629
- const topicQuery = this.config.topics.slice(0, 3).map((t) => `"${t}"`).join(" OR ");
7644
+ const topicQuery = this.config.topics.slice(0, 3).map((t) => this.sanitizeTopic(t)).join(" OR ");
7630
7645
  try {
7631
- const viralQuery = `${topicQuery} min_replies:20 min_faves:50 -is:retweet`;
7646
+ const viralQuery = `(${topicQuery}) -is:retweet has:mentions`;
7632
7647
  logger6.debug(`Searching viral threads with query: ${viralQuery}`);
7633
7648
  const searchResults = await this.twitterClient.fetchSearchTweets(
7634
7649
  viralQuery,
@@ -7636,6 +7651,8 @@ var TwitterDiscoveryClient = class {
7636
7651
  0 /* Top */
7637
7652
  );
7638
7653
  for (const tweet of searchResults.tweets) {
7654
+ const engagementScore = (tweet.likes || 0) + (tweet.retweets || 0) * 2;
7655
+ if (engagementScore < 50) continue;
7639
7656
  const scored = this.scoreTweet(tweet, "thread");
7640
7657
  tweets.push(scored);
7641
7658
  const account = this.scoreAccount({
@@ -7660,7 +7677,8 @@ var TwitterDiscoveryClient = class {
7660
7677
  const accounts = /* @__PURE__ */ new Map();
7661
7678
  for (const topic of this.config.topics.slice(0, 3)) {
7662
7679
  try {
7663
- const influencerQuery = `${topic} -is:retweet min_faves:100 min_retweets:20`;
7680
+ const searchTopic = this.sanitizeTopic(topic);
7681
+ const influencerQuery = `${searchTopic} -is:retweet lang:en`;
7664
7682
  logger6.debug(`Searching for influencers in topic: ${topic}`);
7665
7683
  const results = await this.twitterClient.fetchSearchTweets(
7666
7684
  influencerQuery,
@@ -7668,6 +7686,8 @@ var TwitterDiscoveryClient = class {
7668
7686
  0 /* Top */
7669
7687
  );
7670
7688
  for (const tweet of results.tweets) {
7689
+ const engagement = (tweet.likes || 0) + (tweet.retweets || 0) * 2;
7690
+ if (engagement < 20) continue;
7671
7691
  const scored = this.scoreTweet(tweet, "topic");
7672
7692
  tweets.push(scored);
7673
7693
  const estimatedFollowers = Math.max(