Skip to content

Commit

Permalink
Merge pull request #960 from oxSaturn/fix/MAX_TWEET_LENGTH
Browse files Browse the repository at this point in the history
fix: use MAX_TWEET_LENGTH from setting
  • Loading branch information
odilitime authored Dec 10, 2024
2 parents 9d3ab4c + 055e89c commit 7fe36e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IAgentRuntime } from "@ai16z/eliza";
import { z } from "zod";

const DEFAULT_MAX_TWEET_LENGTH = 280;
export const DEFAULT_MAX_TWEET_LENGTH = 280;

export const twitterEnvSchema = z.object({
TWITTER_DRY_RUN: z
Expand Down
12 changes: 7 additions & 5 deletions packages/client-twitter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Content, Memory, UUID } from "@ai16z/eliza";
import { stringToUuid } from "@ai16z/eliza";
import { ClientBase } from "./base";
import { elizaLogger } from "@ai16z/eliza";

const MAX_TWEET_LENGTH = 280; // Updated to Twitter's current character limit
import { DEFAULT_MAX_TWEET_LENGTH } from "./environment";

export const wait = (minTime: number = 1000, maxTime: number = 3000) => {
const waitTime =
Expand Down Expand Up @@ -170,7 +169,11 @@ export async function sendTweet(
twitterUsername: string,
inReplyTo: string
): Promise<Memory[]> {
const tweetChunks = splitTweetContent(content.text);
const tweetChunks = splitTweetContent(
content.text,
Number(client.runtime.getSetting("MAX_TWEET_LENGTH")) ||
DEFAULT_MAX_TWEET_LENGTH
);
const sentTweets: Tweet[] = [];
let previousTweetId = inReplyTo;

Expand Down Expand Up @@ -236,8 +239,7 @@ export async function sendTweet(
return memories;
}

function splitTweetContent(content: string): string[] {
const maxLength = MAX_TWEET_LENGTH;
function splitTweetContent(content: string, maxLength: number): string[] {
const paragraphs = content.split("\n\n").map((p) => p.trim());
const tweets: string[] = [];
let currentTweet = "";
Expand Down

0 comments on commit 7fe36e2

Please sign in to comment.