@elizaos/plugin-twitter 1.2.8 → 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 +20 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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,
|
|
@@ -7594,7 +7608,7 @@ var TwitterDiscoveryClient = class {
|
|
|
7594
7608
|
const scored = this.scoreTweet(tweet, "topic");
|
|
7595
7609
|
tweets.push(scored);
|
|
7596
7610
|
}
|
|
7597
|
-
const verifiedQuery = `${
|
|
7611
|
+
const verifiedQuery = `${searchTopic} -is:retweet lang:en is:verified`;
|
|
7598
7612
|
logger6.debug(`Searching verified accounts for topic: ${topic}`);
|
|
7599
7613
|
const verifiedResults = await this.twitterClient.fetchSearchTweets(
|
|
7600
7614
|
verifiedQuery,
|
|
@@ -7627,9 +7641,9 @@ var TwitterDiscoveryClient = class {
|
|
|
7627
7641
|
logger6.debug("Discovering from conversation threads...");
|
|
7628
7642
|
const tweets = [];
|
|
7629
7643
|
const accounts = /* @__PURE__ */ new Map();
|
|
7630
|
-
const topicQuery = this.config.topics.slice(0, 3).map((t) =>
|
|
7644
|
+
const topicQuery = this.config.topics.slice(0, 3).map((t) => this.sanitizeTopic(t)).join(" OR ");
|
|
7631
7645
|
try {
|
|
7632
|
-
const viralQuery =
|
|
7646
|
+
const viralQuery = `(${topicQuery}) -is:retweet has:mentions`;
|
|
7633
7647
|
logger6.debug(`Searching viral threads with query: ${viralQuery}`);
|
|
7634
7648
|
const searchResults = await this.twitterClient.fetchSearchTweets(
|
|
7635
7649
|
viralQuery,
|
|
@@ -7663,7 +7677,8 @@ var TwitterDiscoveryClient = class {
|
|
|
7663
7677
|
const accounts = /* @__PURE__ */ new Map();
|
|
7664
7678
|
for (const topic of this.config.topics.slice(0, 3)) {
|
|
7665
7679
|
try {
|
|
7666
|
-
const
|
|
7680
|
+
const searchTopic = this.sanitizeTopic(topic);
|
|
7681
|
+
const influencerQuery = `${searchTopic} -is:retweet lang:en`;
|
|
7667
7682
|
logger6.debug(`Searching for influencers in topic: ${topic}`);
|
|
7668
7683
|
const results = await this.twitterClient.fetchSearchTweets(
|
|
7669
7684
|
influencerQuery,
|