Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use MAX_TWEET_LENGTH from setting #960

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading