Skip to content

Commit

Permalink
Merge pull request #560 from 18F/mgwalker/dad-jokes
Browse files Browse the repository at this point in the history
Bring back dad jokes
  • Loading branch information
mgwalker authored Nov 20, 2024
2 parents a62f092 + b5b90e5 commit c776946
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 126 deletions.
27 changes: 6 additions & 21 deletions src/scripts/dad-joke.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
const { directMention } = require("@slack/bolt");
const axios = require("axios");
const fs = require("node:fs/promises");
const {
cache,
helpMessage,
stats: { incrementStats },
} = require("../utils");
const sample = require("../utils/sample");

module.exports = (app) => {
module.exports = async (app) => {
helpMessage.registerInteractive(
"Dad Jokes",
"dad joke",
"Fetches a joke from Fatherhood.gov. Charlie will first set up the joke, then it'll provide the punchline!",
true,
);

const jokes = JSON.parse(
await fs.readFile("./dad-joke.json", { encoding: "utf-8" }),
);

app.message(
directMention,
/dad joke/i,
async ({ message: { thread_ts: thread }, say }) => {
incrementStats("dad joke");

const jokes = await cache("dad jokes", 60, async () => {
try {
const { data } = await axios.get(
"https://fatherhood.gov/jsonapi/node/dad_jokes",
);

if (data && data.data) {
return data.data.map((joke) => ({
setup: joke.attributes.field_joke_opener,
punchline: joke.attributes.field_joke_response,
}));
}
return [];
} catch (e) {
return [];
}
});

const joke = sample(jokes);
if (joke) {
say({
Expand Down
187 changes: 187 additions & 0 deletions src/scripts/dad-joke.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
[
{
"setup": "Why did the scarecrow win an award?",
"punchline": "He was outstanding in his field."
},
{
"setup": "Did you hear about the two satellites that got married?",
"punchline": "The wedding wasn't much, but the reception was incredible."
},
{ "setup": "February can't March.", "punchline": "But April May!" },
{
"setup": "Why don't crabs ever give to charity?",
"punchline": "Because they're shellfish."
},
{
"setup": "Why did the carpenter leave the lumber store?",
"punchline": "Because he got bored."
},
{
"setup": "Why did the snake go to the doctor?",
"punchline": "Because he had a frog in his throat."
},
{
"setup": "Why did the ghost buy a box of bandages?",
"punchline": "Because he had so many BOO BOOs."
},
{
"setup": "What's the difference between the moon and a cheeseburger?",
"punchline": "The moon is in the sky, a cheeseburger is in THIS guy. (Points to belly)"
},
{
"setup": "If I asked you to choose your favorite feature, would you...",
"punchline": "...pick your nose?"
},
{
"setup": "Why did the astronaut move to the suburbs?",
"punchline": "He wanted more space."
},
{
"setup": "Why did the pizza cutter get a speeding ticket?",
"punchline": "Because he was rounding the corner too fast."
},
{
"setup": "What's big and hairy and wears a bow tie?",
"punchline": "Bigfoot at a fancy party."
},
{
"setup": "Did you hear the one about the Ballerina Debate Team?",
"punchline": "They always stay on point."
},
{
"setup": "Have you heard about the sale at the Optimist Store?",
"punchline": "Everything's 50% on."
},
{
"setup": "Why do optimists have to wear sunglasses?",
"punchline": "Because they're always looking on the bright side."
},
{
"setup": "Where do fancy cats go to the bathroom?",
"punchline": "The glitter box."
},
{
"setup": "Why did the golf course hire the dermatologist?",
"punchline": "It needed to have some moles removed."
},
{
"setup": "Did you hear about the world's greatest watch thief?",
"punchline": "He stole all the time."
},
{
"setup": "Why was the basketball court all wet?",
"punchline": "People kept dribbling all over it."
},
{
"setup": "How do you make a bandstand?",
"punchline": "Take away all of the chairs."
},
{
"setup": "What do you call cheese that's not yours?",
"punchline": "Nacho cheese."
},
{ "setup": "What do you call a fake noodle?", "punchline": "An impasta!" },
{
"setup": "What kind of tree fits in your hand?",
"punchline": "A palm tree."
},
{ "setup": "How do trees get on the internet?", "punchline": "They log on." },
{
"setup": "Did you hear about the new book on anti-gravity?",
"punchline": "It's impossible to put down."
},
{
"setup": "Hear about the guy that got fired from the calendar factory?",
"punchline": "He took too many days off."
},
{
"setup": "Did you hear about the circus fire?",
"punchline": "It was in tents."
},
{
"setup": "Do you know what the loudest pet is?",
"punchline": "A trumpet."
},
{
"setup": "What did the buffalo say to his son when he dropped him off at school?",
"punchline": "Bison"
},
{
"setup": "What did the ocean say to the shore?",
"punchline": "Nothing. It just waved."
},
{
"setup": "What did the beaver say to the tree?",
"punchline": "It's been nice gnawing you."
},
{
"setup": "Hear about the lazy kangaroo?",
"punchline": "He was a real pouch potato."
},
{
"setup": "Did you hear about the restaurant they're building on the moon?",
"punchline": "The food is supposed to be great, but there's no atmosphere."
},
{
"setup": "What do you call a man with a rubber toe?",
"punchline": "Roberto."
},
{
"setup": "Why do you never see elephants hiding in trees?",
"punchline": "Because they're really good at it."
},
{
"setup": "Hear about the guy that wanted to buy a pair of camouflage pants?",
"punchline": "He couldn't find them anywhere."
},
{
"setup": "I couldn't figure out the seat belts in my new car...",
"punchline": "...but then it clicked."
},
{
"setup": "Have you heard the pizza joke that's going around the internet?",
"punchline": "It's a little cheesy."
},
{ "setup": "What's red and smells like paint?", "punchline": "Red paint." },
{
"setup": "Hear about the guy that stayed up all night wondering where the sun had gone?",
"punchline": "It finally dawned on him."
},
{
"setup": "Did you hear that they invented a new type broom?",
"punchline": "It's sweeping the nation."
},
{ "setup": "What is brown and sticky?", "punchline": "A stick." },
{
"setup": "What's more amazing than a talking dog?",
"punchline": "A spelling bee."
},
{
"setup": "A man went to the doctor. He had a cucumber in one ear. A hot dog in the other ear. And two carrots stuck up his nose. He asked the doctor what was wrong with him and the doctor said:",
"punchline": "\"I don't think you're eating properly.\""
},
{
"setup": "What do you call a pony with a sore throat?",
"punchline": "A little horse."
},
{
"setup": "I used to really hate facial hair.",
"punchline": "Then one day, it grew on me."
},
{
"setup": "How many apples grow on an apple tree?",
"punchline": "All of them."
},
{
"setup": "Do you know the name of the boy wizard that loved to play golf?",
"punchline": "Harry Putter."
},
{
"setup": "Why do bees hum?",
"punchline": "Because they don't know the words."
},
{
"setup": "What do you get when you cross a snowman with a vampire?",
"punchline": "Frost-bitten."
}
]
Loading

0 comments on commit c776946

Please sign in to comment.