Skip to content

Commit

Permalink
Merge branch 'v2-develop' of http://github.com/ai16z/eliza into v2-de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
lalalune committed Feb 25, 2025
2 parents 30c048b + d73279e commit 6e02eca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
21 changes: 13 additions & 8 deletions packages/plugin-twitter/src/actions/spaceJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
type Memory,
type State,
stringToUuid,
HandlerCallback
HandlerCallback,
logger
} from "@elizaos/core";
import { Tweet } from "../client";
import { SpaceActivity } from "../spaces";
Expand All @@ -24,7 +25,11 @@ export default {
message: Memory,
_state: State
) => {
if (message.content.source !== "twitter") {
if (message?.content?.source !== "twitter") {
return false;
}

if (!message?.content?.tweet) {
return false;
}

Expand All @@ -41,7 +46,7 @@ export default {
responses: Memory[]
): Promise<boolean> => {
if (!state) {
console.error("State is not available.");
logger.error("State is not available.");
return false;
}

Expand All @@ -61,18 +66,18 @@ export default {
const spaceManager = manager.clients.get(clientKey).space;

if (!spaceManager) {
console.error("space action - no space manager found")
logger.error("space action - no space manager found")
return false;
}

if (spaceManager.spaceStatus !== SpaceActivity.IDLE) {
console.warn("currently hosting/participating a space");
logger.warn("currently hosting/participating a space");
return false;
}

const tweet = message.content.tweet as Tweet;
if (!tweet) {
console.error("space action - no tweet found in message")
logger.warn("space action - no tweet found in message")
return false;
}

Expand All @@ -90,7 +95,7 @@ export default {
return !!spaceJoined;
}
} catch (error) {
console.error("Error joining Twitter Space:", error);
logger.error("Error joining Twitter Space:", error);
}
}
}
Expand All @@ -106,7 +111,7 @@ export default {
}
}
} catch (error) {
console.error(`Error fetching tweets for ${userName}:`, error);
logger.error(`Error fetching tweets for ${userName}:`, error);
}
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-twitter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export class TwitterClientManager {
client.space.startPeriodicSpaceCheck();
}

if (client.post) {
client.post.start();
}

if (client.interaction) {
client.interaction.start();
}
Expand Down
10 changes: 7 additions & 3 deletions packages/plugin-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ export class TwitterInteractionClient {

async start() {
const handleTwitterInteractionsLoop = () => {
// Defaults to 2 minutes
const interactionInterval = (this.state?.TWITTER_POLL_INTERVAL || this.runtime.getSetting("TWITTER_POLL_INTERVAL") as unknown as number || 120) * 1000;

this.handleTwitterInteractions();
setTimeout(
handleTwitterInteractionsLoop,
// Defaults to 2 minutes
(this.state?.TWITTER_POLL_INTERVAL || this.runtime.getSetting("TWITTER_POLL_INTERVAL") as unknown as number) * 1000
interactionInterval
);
};
handleTwitterInteractionsLoop();
Expand Down Expand Up @@ -278,7 +280,9 @@ export class TwitterInteractionClient {
const message = {
content: {
text: tweet.text,
imageUrls: tweet.photos?.map(photo => photo.url) || []
imageUrls: tweet.photos?.map(photo => photo.url) || [],
tweet: tweet,
source: "twitter"
},
agentId: this.runtime.agentId,
userId: userIdUUID,
Expand Down
2 changes: 0 additions & 2 deletions packages/plugin-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export class TwitterPostClient {
"Twitter client initialized in dry run mode - no actual tweets should be posted"
);
}

this.start();
}

async start() {
Expand Down

0 comments on commit 6e02eca

Please sign in to comment.