// Built-in Dad Joke database with content ratings - no external API needed!
const DAD_JOKES_DATABASE = {
// PG RATED JOKES - Clean & Family Friendly
PG: {
general: [
"Why don't scientists trust atoms? Because they make up everything!",
"I told my wife she was drawing her eyebrows too high. She looked surprised.",
"What do you call a fake noodle? An impasta!",
"Why don't eggs tell jokes? They'd crack each other up!",
"What do you call a bear with no teeth? A gummy bear!",
"Why do bicycles fall over? Because they're two tired!",
"What do you call a fish wearing a crown? A king fish!",
"Why don't oysters donate? Because they are shellfish!",
"What do you call a deer with no eyes? No idea!",
"Why don't skeletons fight each other? They don't have the guts!"
],
programming: [
"Why do programmers prefer dark mode? Because light attracts bugs!",
"What's a programmer's favorite hangout place? The Foo Bar!",
"How many programmers does it take to change a light bulb? None, that's a hardware problem!",
"Why do Java developers wear glasses? Because they can't see sharp!",
"What do you call a programmer from Finland? Nerdic!",
"Why don't programmers like nature? It has too many bugs!",
"What's a programmer's favorite music? Algorhythms!",
"What do you call a programmer who doesn't comment their code? A silent partner!",
"Why do front-end developers prefer front-door entrances? They don't have the backend for it!"
],
cats: [
"Why don't cats play poker in the jungle? Too many cheetahs!",
"What do you call a cat that reads? A novel feline!",
"Why did the cat break up with the internet? It couldn't handle the bandwidth!",
"What's a cat's favorite programming language? Purr-l!",
"Why do cats make terrible DJs? Because they have such furry-ocious timing!",
"What do you call a cat that's a magician? Purr-cel!",
"Why don't cats ever get lost? Because they always land on their feet!",
"What's a cat's favorite type of music? Mew-sic!",
"Why did the cat go to medical school? To become a purr-acticing physician!",
"What do you call a cat in a suit? A meow-tie!"
],
food: [
"Why don't eggs tell jokes? They're cracking under pressure!",
"What do you call a fake noodle? An impasta!",
"Why did the scarecrow win an award? He was outstanding in his field!",
"What do you call a bear with no teeth? A gummy bear!",
"Why don't melons ever get married? Because they cantaloupe!",
"What do you call a cheese that isn't yours? Nacho cheese!",
"Why did the coffee file a police report? It got mugged!",
"What do you call a sad strawberry? A blue-berry!",
"Why don't eggs ever tell secrets? Because they might crack under pressure!",
"What do you call fake spaghetti? An impasta!"
]
},
// PG-13 RATED JOKES - Mild Adult Humor
"PG-13": {
general: [
"My wife told me to stop acting like a flamingo, so I had to put my foot down.",
"I told my wife she was drawing her eyebrows too high. She looked surprised.",
"What do you call a fake noodle? An impasta!",
"Why don't eggs tell jokes? They'd crack each other up!",
"What do you call a bear with no teeth? A gummy bear!",
"Why do bicycles fall over? Because they're two tired!",
"What do you call a fish wearing a crown? A king fish!",
"Why don't oysters donate? Because they are shellfish!",
"What do you call a deer with no eyes? No idea!",
"Why don't skeletons fight each other? They don't have the guts!"
],
programming: [
"Why don't programmers like nature? It has too many bugs!",
"What's a programmer's favorite hangout place? The Foo Bar!",
"How many programmers does it take to change a light bulb? None, that's a hardware problem!",
"Why do Java developers wear glasses? Because they can't see sharp!",
"What do you call a programmer from Finland? Nerdic!",
"Why don't programmers like nature? It has too many bugs!",
"What's a programmer's favorite music? Algorhythms!",
"Why do programmers hate coffee? Because it makes them Java-ssi",
"What do you call a programmer who doesn't comment their code? A silent partner!",
"Why do front-end developers prefer front-door entrances? They don't have the backend for it!"
],
cats: [
"Why don't cats play poker in the jungle? Too many cheetahs!",
"What do you call a cat that reads? A novel feline!",
"Why did the cat break up with the internet? It couldn't handle the bandwidth!",
"What's a cat's favorite programming language? Purr-l!",
"Why do cats make terrible DJs? Because they have such furry-ocious timing!",
"What do you call a cat that's a magician? Purr-cel!",
"Why don't cats ever get lost? Because they always land on their feet!",
"What's a cat's favorite type of music? Mew-sic!",
"Why did the cat go to medical school? To become a purr-acticing physician!",
"What do you call a cat in a suit? A meow-tie!"
],
food: [
"Why don't eggs tell jokes? They'd crack each other up!",
"What do you call a fake noodle? An impasta!",
"Why did the scarecrow win an award? He was outstanding before!",
"What do you call a bear with no teeth? A gummy bear!",
"Why don't melons ever get married? Because they cantaloupe!",
"What do you call a cheese that isn't yours? Nacho cheese!",
"Why did the coffee file a police report? It got mugged!",
"What do you call a sad strawberry? A blue-berry!",
"Why don't eggs ever tell secrets? Because they might crack under pressure!",
"What do you call fake pasta? An impasta!"
]
},
// R RATED JOKES - Mature Audiences Only
R: {
general: [
"I told my wife she was drawing her eyebrows too high. She looked surprised.",
"Why did the scarecrow win an award? He was outstanding after!",
"What do you call a fake noodle? An impasta!",
"Why don't eggs tell jokes? They'd crack each other up!",
"What do you call a bear with no teeth? A gummy bear!",
"Why do bicycles fall over? Because they're two tired!",
"What do you call a fish wearing a crown? A king fish!",
"Why don't oysters donate? Because they are shellfish!",
"What do you call a deer with no eyes? No idea!",
"Why don't skeletons fight each other? They don't have the guts!"
],
programming: [
"Why did the programmer quit his job? He didn't get arrays!",
"What's a programmer's favorite drink? Java! And when they're stressed? C#!",
"Why do programmers prefer dark mode? Because light attracts bugs!",
"What's a programmer's favorite hangout place? The Foo Bar!",
"How many programmers does it take to change a light bulb? None, that's a hardware problem!",
"Why do Java developers wear glasses? Because they can't see sharp!",
"What do you call a programmer from Finland? Nerdic!",
"Why don't programmers like nature? It has too many bugs!",
"What's a programmer's favorite music? Algorhythms!",
"Why do programmers hate coffee? Because it makes them Java-ssi"
],
cats: [
"Why don't cats play poker in the jungle? Too many cheetahs!",
"What do you call a cat that reads? A novel feline!",
"Why did the cat break up with the internet? It couldn't handle the bandwidth!",
"What's a cat's favorite programming language? Purr-l!",
"Why do cats make terrible DJs? Because they have such furry-ocious timing!",
"What do you call a cat that's a magician? Purr-cel!",
"Why don't cats ever get lost? Because they always land on their feet!",
"What's a cat's favorite type of music? Mew-sic!",
"Why did the cat go to medical school? To become a purr-acticing physician!",
"What do you call a cat in a suit? A meow-tie!"
],
food: [
"Why don't eggs tell jokes? They'd crack each other up!",
"What do you call a fake noodle? An impasta!",
"Why did the scarecrow win an award? He was outstanding after!",
"What do you call a bear with no teeth? A gummy bear!",
"Why don't melons ever get married? Because they cantaloupe!",
"What do you call a cheese that isn't yours? Nacho cheese!",
"Why did the coffee file a police report? It got mugged!",
"What do you call a sad strawberry? A blue-berry!",
"Why don't eggs ever tell secrets? Because they might crack under pressure!",
"What do you call fake spaghetti? An impasta!"
]
}
};
export async function generateDadJoke(topic?: string, rating?: string): Promise<string> {
try {
// Normalize rating - default to PG-13
const normalizedRating = rating || 'PG-13';
// Normalize topic for database lookup
const normalizedTopic = topic?.toLowerCase().trim() || 'general';
// Select appropriate joke category based on rating first
let jokeDatabase = DAD_JOKES_DATABASE[normalizedRating as keyof typeof DAD_JOKES_DATABASE];
if (!jokeDatabase) {
jokeDatabase = DAD_JOKES_DATABASE['PG-13']; // Fallback to PG-13
}
// Then select topic category
let jokeCategory: string[];
if (normalizedTopic && jokeDatabase[normalizedTopic as keyof typeof jokeDatabase]) {
jokeCategory = jokeDatabase[normalizedTopic as keyof typeof jokeDatabase];
} else if (normalizedTopic === 'programming' || normalizedTopic === 'code' || normalizedTopic === 'coding') {
jokeCategory = jokeDatabase.programming;
} else if (normalizedTopic === 'cat' || normalizedTopic === 'cats' || normalizedTopic === 'kitten') {
jokeCategory = jokeDatabase.cats;
} else if (normalizedTopic === 'food' || normalizedTopic === 'eating' || normalizedTopic === 'cooking') {
jokeCategory = jokeDatabase.food;
} else {
jokeCategory = jokeDatabase.general;
}
// Randomly select a joke from the appropriate category
const randomIndex = Math.floor(Math.random() * jokeCategory.length);
const selectedJoke = jokeCategory[randomIndex];
console.log(`🎭 Generated ${normalizedRating} Dad Joke - Topic: ${normalizedTopic}`);
return selectedJoke;
} catch (error) {
console.error('Error generating Dad Joke:', error);
// Fallback to PG general joke
const fallbackJokes = DAD_JOKES_DATABASE.PG.general;
const randomIndex = Math.floor(Math.random() * fallbackJokes.length);
return fallbackJokes[randomIndex];
}
}