Skip to content

Commit

Permalink
refactor: extracted duplicated code to getRandomEmoji function
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoBaroso committed Jun 7, 2024
1 parent 1b8149b commit 2cdffbc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pages/api/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export async function shareNewApply(name: string) {
handleError(e, "Error retrieving count");
}
const counterMessage = counter ?? "Unknown";
const emoji1 = ["🔥", "✨", "👾"][Math.floor(Math.random() * 3)];
const emoji2 = ["🥳", "🤩", "😍"][Math.floor(Math.random() * 3)];
const emoji1 = getRandomEmoji(["🔥", "✨", "👾"]);
const emoji2 = getRandomEmoji(["🥳", "🤩", "😍"]);
const message = `${emoji1} Nuova Candidatura! ${emoji2}\nNome: ${name}\nCount: ${counterMessage}`;
await sendMessage(message);
}
Expand Down Expand Up @@ -55,3 +55,7 @@ function isFileOlderThanNDays(filePath: string, days: number): boolean {
const thirtyDaysInMilliseconds = days * 24 * 60 * 60 * 1000; // days in ms
return now - lastUpdated > thirtyDaysInMilliseconds;
}

function getRandomEmoji(emojis: string[]): string {
return emojis[Math.floor(Math.random() * emojis.length)];
}

0 comments on commit 2cdffbc

Please sign in to comment.