chore: lint

This commit is contained in:
2025-12-23 15:48:34 -08:00
parent 5925f3aec0
commit 6d89b2772b
2 changed files with 45 additions and 43 deletions
+43 -42
View File
@@ -11,49 +11,50 @@ import { TwitterApi } from "twitter-api-v2";
* @param content - The main body of the announcement. * @param content - The main body of the announcement.
* @returns A message indicating the success or failure of the operation. * @returns A message indicating the success or failure of the operation.
*/ */
export const announceOnTwitter = async(content: Array<string>): Promise<string> => { export const announceOnTwitter
if ( = async(content: Array<string>): Promise<string> => {
process.env.TWITTER_CONSUMER_KEY === undefined if (
process.env.TWITTER_CONSUMER_KEY === undefined
|| process.env.TWITTER_CONSUMER_SECRET === undefined || process.env.TWITTER_CONSUMER_SECRET === undefined
|| process.env.TWITTER_TOKEN === undefined || process.env.TWITTER_TOKEN === undefined
|| process.env.TWITTER_SECRET === undefined || process.env.TWITTER_SECRET === undefined
) { ) {
return "Twitter credentials are not set."; return "Twitter credentials are not set.";
} }
const twitterClient = new TwitterApi({ const twitterClient = new TwitterApi({
accessSecret: process.env.TWITTER_SECRET, accessSecret: process.env.TWITTER_SECRET,
accessToken: process.env.TWITTER_TOKEN, accessToken: process.env.TWITTER_TOKEN,
appKey: process.env.TWITTER_CONSUMER_KEY, appKey: process.env.TWITTER_CONSUMER_KEY,
appSecret: process.env.TWITTER_CONSUMER_SECRET, appSecret: process.env.TWITTER_CONSUMER_SECRET,
}); });
const [ firstPost, ...restOfPosts ] = content; const [ firstPost, ...restOfPosts ] = content;
const failedReplies: Array<string> = []; const failedReplies: Array<string> = [];
if (firstPost === undefined) { if (firstPost === undefined) {
return "No posts to send to Twitter."; return "No posts to send to Twitter.";
} }
const result = await twitterClient.v2. const result = await twitterClient.v2.
tweet(firstPost). tweet(firstPost).
catch((error: unknown) => { catch((error: unknown) => {
return error instanceof Error return error instanceof Error
? error.message ? error.message
: String(error); : String(error);
}); });
if (typeof result === "string") { if (typeof result === "string") {
return `Failed to send message to Twitter. ${result}`; return `Failed to send message to Twitter. ${result}`;
} }
let { id } = result.data; let { id } = result.data;
for (const post of restOfPosts) { for (const post of restOfPosts) {
// eslint-disable-next-line no-await-in-loop -- We need to do this sequentially. // eslint-disable-next-line no-await-in-loop -- We need to do this sequentially.
const twitterResponse = await twitterClient.v2.reply(post, id); const twitterResponse = await twitterClient.v2.reply(post, id);
if (typeof twitterResponse !== "string") { if (typeof twitterResponse !== "string") {
const { id: replyId } = twitterResponse.data; const { id: replyId } = twitterResponse.data;
id = replyId; id = replyId;
continue; continue;
} }
failedReplies.push(post); failedReplies.push(post);
} }
return `Successfully sent initial post to Twitter. ${failedReplies.length > 0 return `Successfully sent initial post to Twitter. ${failedReplies.length > 0
? `Failed to send ${failedReplies.length.toString()} replies: ${failedReplies.join(", ")}` ? `Failed to send ${failedReplies.length.toString()} replies: ${failedReplies.join(", ")}`
: `All ${(content.length - 1).toString()} replies were sent successfully.`}`; : `All ${(content.length - 1).toString()} replies were sent successfully.`}`;
}; };
+2 -1
View File
@@ -11,7 +11,8 @@ import {
announcementSystemMessage, announcementSystemMessage,
} from "../config/announcements.js"; } from "../config/announcements.js";
import { getAiCost } from "../utils/getAiCost.js"; import { getAiCost } from "../utils/getAiCost.js";
import type { AnnouncementResponse } from "../interfaces/announcementResponse.js"; import type { AnnouncementResponse }
from "../interfaces/announcementResponse.js";
/** /**
* Generates announcements for all platforms using AI. * Generates announcements for all platforms using AI.