simpsonize-me
Version:
Generate random quotes from The Simpsons characters - D'oh! Get your daily dose of Springfield wisdom
179 lines (164 loc) • 5.39 kB
JavaScript
const quotes = {
homer: [
"D'oh!",
"Mmm... beer.",
"Why you little...",
"Woo-hoo!",
"I'm not a bad guy! I work hard, and I love my kids. So why should I spend half my Sunday hearing about how I'm going to Hell?",
"To alcohol! The cause of... and solution to... all of life's problems.",
"Kids, you tried your best and you failed miserably. The lesson is, never try.",
"I'm in no condition to drive... wait! I shouldn't listen to myself, I'm drunk!",
"Facts are meaningless. You could use facts to prove anything that's even remotely true!"
],
bart: [
"Eat my shorts!",
"Don't have a cow, man!",
"Ay, caramba!",
"I didn't do it!",
"Cowabunga!",
"I'm Bart Simpson, who the hell are you?",
"Nobody better lay a finger on my butterfinger!",
"Get bent!",
"Cool your jets, man!"
],
marge: [
"Mmm-hmm.",
"Homer!",
"I just think they're neat!",
"Oh my.",
"That's not how you spell 'definitely'.",
"I'm not going to live in a house of evil!",
"Homer, is this how you pictured married life?",
"I think we should discuss this as a family."
],
lisa: [
"If anyone wants me, I'll be in my room.",
"I'll be in the car, dudes!",
"Dad, we did something very bad!",
"Bart!",
"This is indeed a disturbing universe.",
"I'm going to become a vegetarian.",
"The answers aren't in those books anymore!",
"I am the lizard queen!"
],
moe: [
"Moe's Tavern, Moe speaking.",
"Hey, I got a right to defend myself!",
"What's a diorama?",
"I'm better than dirt! Well, most kinds of dirt. I mean, not that fancy store-bought dirt. That stuff's loaded with nutrients!",
"That's a right pretty dress, Marge."
],
burns: [
"Excellent.",
"Release the hounds!",
"Smithers, who is that man?",
"Bah! Fiddlesticks!",
"I'd give it all up, for just a little more.",
"A lifetime of working with nuclear power has left me with a healthy green glow... and left me as impotent as a Nevada boxing commissioner.",
"Family, religion, friendship. These are the three demons you must slay if you wish to succeed in business."
],
ned: [
"Okily dokily!",
"Diddly!",
"Hi-diddly-ho, neighborino!",
"Stupid Flanders!",
"I've done everything the Bible says — even the stuff that contradicts the other stuff!",
"Well howdy, neighbor!",
"Feels like I'm wearing nothing at all!"
]
};
const allQuotes = Object.values(quotes).flat();
/**
* Get a random Simpsons quote
* @param {string} character - Optional character name (homer, bart, marge, lisa, moe, burns, ned)
* @returns {Object} Quote object with text and character
*/
function getRandomQuote(character = null) {
if (character && quotes[character.toLowerCase()]) {
const characterQuotes = quotes[character.toLowerCase()];
const randomQuote = characterQuotes[Math.floor(Math.random() * characterQuotes.length)];
return {
quote: randomQuote,
character: character.toLowerCase(),
characterDisplay: character.charAt(0).toUpperCase() + character.slice(1)
};
}
// Get random quote from all characters
const randomQuote = allQuotes[Math.floor(Math.random() * allQuotes.length)];
// Find which character said it
let foundCharacter = 'unknown';
for (const [char, charQuotes] of Object.entries(quotes)) {
if (charQuotes.includes(randomQuote)) {
foundCharacter = char;
break;
}
}
return {
quote: randomQuote,
character: foundCharacter,
characterDisplay: foundCharacter.charAt(0).toUpperCase() + foundCharacter.slice(1)
};
}
/**
* Get all available characters
* @returns {Array} Array of character names
*/
function getAvailableCharacters() {
return Object.keys(quotes);
}
/**
* Get all quotes for a specific character
* @param {string} character - Character name
* @returns {Array} Array of quotes for the character
*/
function getCharacterQuotes(character) {
if (!character || !quotes[character.toLowerCase()]) {
return [];
}
return quotes[character.toLowerCase()];
}
/**
* Get multiple random quotes
* @param {number} count - Number of quotes to return (default: 5, max: 20)
* @param {string} character - Optional character name
* @returns {Array} Array of quote objects
*/
function getMultipleQuotes(count = 5, character = null) {
const maxCount = Math.min(count, 20);
const quotesArray = [];
for (let i = 0; i < maxCount; i++) {
quotesArray.push(getRandomQuote(character));
}
return quotesArray;
}
/**
* Search quotes by keyword
* @param {string} keyword - Keyword to search for
* @returns {Array} Array of matching quote objects
*/
function searchQuotes(keyword) {
if (!keyword || typeof keyword !== 'string') {
return [];
}
const results = [];
const searchTerm = keyword.toLowerCase();
for (const [character, characterQuotes] of Object.entries(quotes)) {
characterQuotes.forEach(quote => {
if (quote.toLowerCase().includes(searchTerm)) {
results.push({
quote: quote,
character: character,
characterDisplay: character.charAt(0).toUpperCase() + character.slice(1)
});
}
});
}
return results;
}
module.exports = {
getRandomQuote,
getAvailableCharacters,
getCharacterQuotes,
getMultipleQuotes,
searchQuotes
};