From 33c7b25bd2dcab30a26eaa19c9b99bcee094cede Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Fri, 28 Oct 2022 05:06:48 +0200 Subject: [PATCH] Added riddles. --- assets/riddle-dedupe.js | 19 + assets/riddles.json | 1177 ++++++++++++++++++++++++++++++++++++++- config/default.js | 4 + src/games/riddle.js | 49 +- src/play.js | 2 +- 5 files changed, 1245 insertions(+), 6 deletions(-) create mode 100644 assets/riddle-dedupe.js diff --git a/assets/riddle-dedupe.js b/assets/riddle-dedupe.js new file mode 100644 index 0000000..c34b10f --- /dev/null +++ b/assets/riddle-dedupe.js @@ -0,0 +1,19 @@ +'use strict'; + +const riddles = require('./riddles.json'); + +function init() { + const answers = new Map(); + + riddles.forEach((riddle) => { + riddle.answers.forEach((answer) => { + if (answers.has(answer)) { + console.log(`Possible duplicate, answer '${answer}' for ${riddle.riddle} ||| ${answers.get(answer).riddle}`); + } + + answers.set(answer, riddle); + }); + }); +} + +init(); diff --git a/assets/riddles.json b/assets/riddles.json index d8e0a5f..89bf7a3 100644 --- a/assets/riddles.json +++ b/assets/riddles.json @@ -1,6 +1,1175 @@ [ - { - "riddle": "What has to be broken before you can use it?", - "answer": "An egg." - } + { + "riddle": "I’m tall when I’m young, and I’m short when I’m old. What am I?", + "answers": [ + "candle" + ], + "fullAnswer": "A candle" + }, + { + "riddle": "What month of the year has 28 days?", + "answers": [ + "all of them" + ], + "fullAnswer": "All of them" + }, + { + "riddle": "What is full of holes but still holds water?", + "answers": [ + "sponge" + ], + "fullAnswer": "A sponge" + }, + { + "riddle": ": What question can you never answer yes to?", + "answers": [ + "are you asleep", + "are you sleeping" + ], + "fullAnswer": "Are you asleep yet?" + }, + { + "riddle": "What is always in front of you but can’t be seen?", + "answers": [ + "future" + ], + "fullAnswer": "The future" + }, + { + "riddle": "There’s a one-story house in which everything is yellow. Yellow walls, yellow doors, yellow furniture. What color are the stairs?", + "answers": [ + "no stairs", + "aren't any stairs" + ], + "fullAnswer": "There aren’t any stairs. It’s a one-story house." + }, + { + "riddle": "What can you break, even if you never pick it up or touch it?", + "answers": [ + "promise" + ], + "fullAnswer": "A promise" + }, + { + "riddle": "What goes up but never comes down?", + "answers": [ + "age" + ], + "fullAnswer": "Your age" + }, + { + "riddle": "A man who was outside in the rain without an umbrella or hat didn’t get a single hair on his head wet. Why?", + "answers": [ + "bald", + "no hair", + "have any hair" + ], + "fullAnswer": "He was bald." + }, + { + "riddle": "I shave every day, but my beard stays the same. What am I?", + "answers": [ + "barber", + "hairdresser" + ], + "fullAnswer": "A barber" + }, + { + "riddle": "You see a boat filled with people, yet there isn’t a single person on board. How is that possible?", + "answers": [ + "married" + ], + "fullAnswer": "All the people on the boat are married." + }, + { + "riddle": "You walk into a room that contains a match, a kerosene lamp, a candle and a fireplace. What would you light first?", + "answers": [ + "match" + ], + "fullAnswer": "The match" + }, + { + "riddle": "I have branches, but no fruit, trunk or leaves. What am I?", + "answers": [ + "bank" + ], + "fullAnswer": "A bank" + }, + { + "riddle": "What can’t talk but will reply when spoken to?", + "answers": [ + "echo" + ], + "fullAnswer": "An echo" + }, + { + "riddle": "The more of this there is, the less you see. What is it?", + "answers": [ + "darkness" + ], + "fullAnswer": "Darkness" + }, + { + "riddle": "I follow you all the time and copy your every move, but you can’t touch me or catch me. What am I?", + "answers": [ + "shadow" + ], + "fullAnswer": "Your shadow" + }, + { + "riddle": "What has many keys but can’t open a single lock?", + "answers": [ + "piano" + ], + "fullAnswer": "A piano" + }, + { + "riddle": "What can you hold in your left hand but not in your right?", + "answers": [ + "right elbow" + ], + "fullAnswer": "Your right elbow" + }, + { + "riddle": "What is black when it’s clean and white when it’s dirty?", + "answers": [ + "chalkboard", + "blackboard" + ], + "fullAnswer": "A chalkboard" + }, + { + "riddle": "I’m light as a feather, yet the strongest person can’t hold me for five minutes. What am I?", + "answers": [ + "breath" + ], + "fullAnswer": "Your breath" + }, + { + "riddle": "Where does today come before yesterday?", + "answers": [ + "dictionary" + ], + "fullAnswer": "The dictionary" + }, + { + "riddle": "What invention lets you look right through a wall?", + "answers": [ + "window" + ], + "fullAnswer": "A window" + }, + { + "riddle": "If you’ve got me, you want to share me; if you share me, you haven’t kept me. What am I?", + "answers": [ + "secret" + ], + "fullAnswer": "A secret" + }, + { + "riddle": "What can’t be put in a saucepan?", + "answers": [ + "lid" + ], + "fullAnswer": "Its lid" + }, + { + "riddle": "What goes up and down but doesn’t move?", + "answers": [ + "staircase" + ], + "fullAnswer": "A staircase" + }, + { + "riddle": "It belongs to you, but other people use it more than you do. What is it?", + "answers": [ + "name" + ], + "fullAnswer": "Your name" + }, + { + "riddle": "What has lots of eyes, but can’t see?", + "answers": [ + "potato" + ], + "fullAnswer": "A potato" + }, + { + "riddle": "What has one eye, but can’t see?", + "answers": [ + "needle" + ], + "fullAnswer": "A needle" + }, + { + "riddle": "What has many needles, but doesn’t sew?", + "answers": [ + "christmas tree", + "pine tree" + ], + "fullAnswer": "A Christmas tree" + }, + { + "riddle": "What has hands, but can’t clap?", + "answers": [ + "clock" + ], + "fullAnswer": "A clock" + }, + { + "riddle": "What has one head, one foot and four legs?", + "answers": [ + "bed" + ], + "fullAnswer": "A bed" + }, + { + "riddle": "What can you catch, but not throw?", + "answers": [ + "cold" + ], + "fullAnswer": "A cold" + }, + { + "riddle": "What has many teeth, but can’t bite?", + "answers": [ + "comb" + ], + "fullAnswer": "A comb" + }, + { + "riddle": "What is cut on a table, but is never eaten?", + "answers": [ + "deck of cards" + ], + "fullAnswer": "A deck of cards" + }, + { + "riddle": "What has words, but never speaks?", + "answers": [ + "book" + ], + "fullAnswer": "A book" + }, + { + "riddle": "What runs all around a backyard, yet never moves?", + "answers": [ + "fence" + ], + "fullAnswer": "A fence" + }, + { + "riddle": "What can travel all around the world without leaving its corner?", + "answers": [ + "stamp" + ], + "fullAnswer": "A stamp" + }, + { + "riddle": "What has a head and a tail but no body?", + "answers": [ + "coin" + ], + "fullAnswer": "A coin" + }, + { + "riddle": "Where does one wall meet the other wall?", + "answers": [ + "corner" + ], + "fullAnswer": "On the corner" + }, + { + "riddle": "What building has the most stories?", + "answers": [ + "library" + ], + "fullAnswer": "The library" + }, + { + "riddle": "What tastes better than it smells?", + "answers": [ + "tongue" + ], + "fullAnswer": "Your tongue" + }, + { + "riddle": "What has 13 hearts, but no other organs?", + "answers": [ + "cards" + ], + "fullAnswer": "A deck of cards" + }, + { + "riddle": "It stalks the countryside with ears that can’t hear. What is it?", + "answers": [ + "corn" + ], + "fullAnswer": "Corn" + }, + { + "riddle": "What kind of coat is best put on wet?", + "answers": [ + "paint" + ], + "fullAnswer": "A coat of paint" + }, + { + "riddle": "What has a bottom at the top?", + "answers": [ + "legs" + ], + "fullAnswer": "Your legs" + }, + { + "riddle": "What has four wheels and flies?", + "answers": [ + "garbage truck" + ], + "fullAnswer": "A garbage truck" + }, + { + "riddle": "I am an odd number. Take away a letter and I become even. What number am I?", + "answers": [ + "seven" + ], + "fullAnswer": "Seven" + }, + { + "riddle": "If two’s company, and three’s a crowd, what are four and five?", + "answers": [ + "nine" + ], + "fullAnswer": "Nine" + }, + { + "riddle": "What three numbers, none of which is zero, give the same result whether they’re added or multiplied?", + "answers": [ + "one, two and three", + "one two and three", + "one, two, three", + "one two three", + "1, 2, 3", + "1 2 3", + "1, 2 and 3", + "1 2 and 3" + ], + "fullAnswer": "One, two and three" + }, + { + "riddle": "Mary has four daughters, and each of her daughters has a brother. How many children does Mary have?", + "answers": [ + "five", + "5" + ], + "fullAnswer": "Five—each daughter has the same brother." + }, + { + "riddle": "Which is heavier: a ton of bricks or a ton of feathers?", + "answers": [ + "neither", + "none" + ], + "fullAnswer": "Neither—they both weigh a ton." + }, + { + "riddle": "Three doctors said that Bill was their brother. Bill says he has no brothers. How many brothers does Bill actually have?", + "answers": [ + "none", + "zero" + ], + "fullAnswer": "None. He has three sisters." + }, + { + "riddle": "Two fathers and two sons are in a car, yet there are only three people in the car. How?", + "answers": [ + "grandfather, father and son", + "father, grandfather and son" + ], + "fullAnswer": "They are a grandfather, father and son" + }, + { + "riddle": "The day before yesterday I was 21, and next year I will be 24. When is my birthday?", + "answers": [ + "december 31", + "31 december", + "31th of december" + ], + "fullAnswer": "December 31; today is January 1" + }, + { + "riddle": "A little girl goes to the store and buys one dozen eggs. As she is going home, all but three break. How many eggs are left unbroken?", + "answers": [ + "three", + "3" + ], + "fullAnswer": "Three" + }, + { + "riddle": "A man describes his daughters, saying, “They are all blonde, but two; all brunette but two; and all redheaded but two.” How many daughters does he have?", + "answers": [ + "three", + "3" + ], + "fullAnswer": "Three: A blonde, a brunette and a redhead" + }, + { + "riddle": "What five-letter word becomes shorter when you add two letters to it?", + "answers": [ + "short" + ], + "fullAnswer": "Short" + }, + { + "riddle": "What begins with an \"e\" and only contains one letter?", + "answers": [ + "envelope" + ], + "fullAnswer": "An envelope" + }, + { + "riddle": "A word I know, six letters it contains, remove one letter and 12 remains. What is it?", + "answers": [ + "dozens" + ], + "fullAnswer": "Dozens" + }, + { + "riddle": "What would you find in the middle of Toronto?", + "answers": [ + "o" + ], + "fullAnswer": "The letter “o”" + }, + { + "riddle": "Two in a corner, one in a room, zero in a house, but one in a shelter. What is it?", + "answers": [ + "r" + ], + "fullAnswer": "The letter “r”" + }, + { + "riddle": "I am the beginning of everything, the end of everywhere. I'm the beginning of eternity, the end of time and space. What am I?", + "answers": [ + "e" + ], + "fullAnswer": "Also the letter “e”" + }, + { + "riddle": "What 4-letter word can be written forward, backward or upside down, and can still be read from left to right?", + "answers": [ + "noon" + ], + "fullAnswer": "NOON" + }, + { + "riddle": "Forward I am heavy, but backward I am not. What am I?", + "answers": [ + "not" + ], + "fullAnswer": "The word “not”" + }, + { + "riddle": "What is 3/7 chicken, 2/3 cat and 2/4 goat?", + "answers": [ + "chicago" + ], + "fullAnswer": "Chicago" + }, + { + "riddle": "I am a word of letters three; add two and fewer there will be. What word am I?", + "answers": [ + "few" + ], + "fullAnswer": "Few" + }, + { + "riddle": "What is the end of everything?", + "answers": [ + "g" + ], + "fullAnswer": "The letter “g”" + }, + { + "riddle": "What word is pronounced the same if you take away four of its five letters?", + "answers": [ + "queue" + ], + "fullAnswer": "Queue" + }, + { + "riddle": "I am a word that begins with the letter “i.” If you add the letter “a” to me, I become a new word with a different meaning, but that sounds exactly the same. What word am I?", + "answers": [ + "isle" + ], + "fullAnswer": "Isle (add “a” to make “aisle”)" + }, + { + "riddle": "What word in the English language does the following: The first two letters signify a male, the first three letters signify a female, the first four letters signify a great, while the entire world signifies a great woman. What is the word?", + "answers": [ + "heroine" + ], + "fullAnswer": "Heroine" + }, + { + "riddle": "What is so fragile that saying its name breaks it?", + "answers": [ + "silence" + ], + "fullAnswer": "Silence" + }, + { + "riddle": "What can run but never walks, has a mouth but never talks, has a head but never weeps, has a bed but never sleeps?", + "answers": [ + "river" + ], + "fullAnswer": "A river" + }, + { + "riddle": "Speaking of rivers, a man calls his dog from the opposite side of the river. The dog crosses the river without getting wet, and without using a bridge or boat. How?", + "answers": [ + "frozen", + "ice" + ], + "fullAnswer": "The river was frozen." + }, + { + "riddle": "What can fill a room but takes up no space?", + "answers": [ + "light" + ], + "fullAnswer": "Light" + }, + { + "riddle": "The more you take, the more you leave behind. What are they?", + "answers": [ + "footsteps" + ], + "fullAnswer": "Footsteps" + }, + { + "riddle": "I turn once, what is out will not get in. I turn again, what is in will not get out. What am I?", + "answers": [ + "key" + ], + "fullAnswer": "A key" + }, + { + "riddle": "People make me, save me, change me, raise me. What am I?", + "answers": [ + "money" + ], + "fullAnswer": "Money" + }, + { + "riddle": "What breaks yet never falls, and what falls yet never breaks?", + "answers": [ + "day, and night", + "day and night" + ], + "fullAnswer": "Day, and night" + }, + { + "riddle": "What goes through cities and fields, but never moves?", + "answers": [ + "road" + ], + "fullAnswer": "A road" + }, + { + "riddle": "I am always hungry and will die if not fed, but whatever I touch will soon turn red. What am I?", + "answers": [ + "fire" + ], + "fullAnswer": "Fire" + }, + { + "riddle": "The person who makes it has no need of it; the person who buys it has no use for it. The person who uses it can neither see nor feel it. What is it?", + "answers": [ + "coffin", + "casket" + ], + "fullAnswer": "A coffin" + }, + { + "riddle": "A man looks at a painting in a museum and says, “Brothers and sisters I have none, but that man’s father is my father’s son.” Who is in the painting?", + "answers": [ + "son" + ], + "fullAnswer": "The man’s son" + }, + { + "riddle": "With pointed fangs I sit and wait; with piercing force I crunch out fate; grabbing victims, proclaiming might; physically joining with a single bite. What am I?", + "answers": [ + "stapler" + ], + "fullAnswer": "A stapler" + }, + { + "riddle": "Which letter of the alphabet has the most water?", + "answers": [ + "c" + ], + "fullAnswer": "C" + }, + { + "riddle": "What kind of dog keeps the best time?", + "answers": [ + "watchdog" + ], + "fullAnswer": "Watchdog" + }, + { + "riddle": "Laughing Out", + "answers": [ + "loud" + ], + "fullAnswer": "Loud" + }, + { + "riddle": "A tasty reward given to well behaved dogs and kids", + "answers": [ + "treat" + ], + "fullAnswer": "Treat" + }, + { + "riddle": "A caribbean shape that makes ships disappear", + "answers": [ + "triangle" + ], + "fullAnswer": "Triangle" + }, + { + "riddle": "It takes two people to do this", + "answers": [ + "tango" + ], + "fullAnswer": "Tango" + }, + { + "riddle": "What has a face and two hands, but no arms or legs?", + "answers": [ + "clock" + ], + "fullAnswer": "Clock" + }, + { + "riddle": "What has a neck but no head?", + "answers": [ + "bottle" + ], + "fullAnswer": "Bottle" + }, + { + "riddle": "What type of cheese is made backwards?", + "answers": [ + "edam" + ], + "fullAnswer": "Edam" + }, + { + "riddle": "What gets wetter as it dries?", + "answers": [ + "towel" + ], + "fullAnswer": "Towel" + }, + { + "riddle": "What starts with a 'P', ends with an 'E' and has thousands of letters?", + "answers": [ + "post office" + ], + "fullAnswer": "Post Office" + }, + { + "riddle": "What has to be broken before you can eat it?", + "answers": [ + "egg" + ], + "fullAnswer": "Egg" + }, + { + "riddle": "What begins with T, ends with T and has T in it?", + "answers": [ + "teapot" + ], + "fullAnswer": "Teapot" + }, + { + "riddle": "Teddy bears are never hungry because they are always what?", + "answers": [ + "stuffed" + ], + "fullAnswer": "Stuffed" + }, + { + "riddle": "The more you take aways, the larger it becomes? What is it?", + "answers": [ + "hole" + ], + "fullAnswer": "Hole" + }, + { + "riddle": "Where do fish keep their money?", + "answers": [ + "riverbank" + ], + "fullAnswer": "Riverbank" + }, + { + "riddle": "What do you get when you cross an automobile with a household animal?", + "answers": [ + "carpet" + ], + "fullAnswer": "Carpet" + }, + { + "riddle": "Mary's father has 4 children; three are named Nana, Nene, and Nini. So what is the 4th child's name?", + "answers": [ + "mary" + ], + "fullAnswer": "Mary" + }, + { + "riddle": "What bone has a sense of humor?", + "answers": [ + "humorous" + ], + "fullAnswer": "Humorous" + }, + { + "riddle": "What has four fingers and one thumb, but is not alive?", + "answers": [ + "glove" + ], + "fullAnswer": "Glove" + }, + { + "riddle": "What flies without wings?", + "answers": [ + "time" + ], + "fullAnswer": "Time" + }, + { + "riddle": "What turns everything around, but does not move?", + "answers": [ + "mirror" + ], + "fullAnswer": "Mirror" + }, + { + "riddle": "What is half of two plus two?", + "answers": [ + "three" + ], + "fullAnswer": "Three" + }, + { + "riddle": "What word looks the same upside down and backwards?", + "answers": [ + "swims" + ], + "fullAnswer": "Swims" + }, + { + "riddle": "What kind of fish chases a mouse?", + "answers": [ + "catfish" + ], + "fullAnswer": "Catfish" + }, + { + "riddle": "Your mother's brother's only brother-in-law is asleep on your coach. Who is asleep on your couch?", + "answers": [ + "dad" + ], + "fullAnswer": "Dad" + }, + { + "riddle": "What's the difference between here and there?", + "answers": [ + "t" + ], + "fullAnswer": "T" + }, + { + "riddle": "What goes up and down without moving?", + "answers": [ + "stairs" + ], + "fullAnswer": "Stairs" + }, + { + "riddle": "Take off my skin and I won't cry, but you will, What am I?", + "answers": [ + "onion" + ], + "fullAnswer": "Onion" + }, + { + "riddle": "What doesn't get any wetter, no matter how much rain falls on it?", + "answers": [ + "water" + ], + "fullAnswer": "Water" + }, + { + "riddle": "I have a face, two arms, and two hands, yet I can not move. I count to twelve, yet I can not speak. I can still tell you something everyday.", + "answers": [ + "clock" + ], + "fullAnswer": "Clock" + }, + { + "riddle": "What is round on both ends and hi in the middle?", + "answers": [ + "ohio" + ], + "fullAnswer": "Ohio" + }, + { + "riddle": "What do you call a dog that sweats so much?", + "answers": [ + "hotdog" + ], + "fullAnswer": "Hotdog" + }, + { + "riddle": "What do you call a rabbit with fleas?", + "answers": [ + "bugs bunny" + ], + "fullAnswer": "Bugs Bunny" + }, + { + "riddle": "What rains at the north pole?", + "answers": [ + "reindeer" + ], + "fullAnswer": "Reindeer" + }, + { + "riddle": "What kind of apple has a short temper?", + "answers": [ + "crabapple" + ], + "fullAnswer": "Crabapple" + }, + { + "riddle": "What do you do with a dead chemist?", + "answers": [ + "barium" + ], + "fullAnswer": "Barium" + }, + { + "riddle": "What calls for help, when written in capital letters, is the same forwards, backwards and upside down?", + "answers": [ + "sos" + ], + "fullAnswer": "SOS" + }, + { + "riddle": "What body part is pronounced as one letter but written with three, only two different letters are used?", + "answers": [ + "eye" + ], + "fullAnswer": "Eye" + }, + { + "riddle": "What is 2+2? What is 4+4? What is 8+8? What is 16+16? Pick a number between 12 and 5", + "answers": [ + "seven" + ], + "fullAnswer": "Seven" + }, + { + "riddle": "Feed me and I live, give me something to drink and i'll die, What am I?", + "answers": [ + "fire" + ], + "fullAnswer": "Fire" + }, + { + "riddle": "What keeps things green and keeps kids occupied in the summertime?", + "answers": [ + "sprinkler" + ], + "fullAnswer": "Sprinkler" + }, + { + "riddle": "Old Mcdonald had this", + "answers": [ + "farm" + ], + "fullAnswer": "Farm" + }, + { + "riddle": "Poorly behaved children often find themselves sitting in these", + "answers": [ + "corner" + ], + "fullAnswer": "Corner" + }, + { + "riddle": "Brings you may flowers", + "answers": [ + "showers" + ], + "fullAnswer": "Showers" + }, + { + "riddle": "A shower that lights up the sky", + "answers": [ + "meteor" + ], + "fullAnswer": "Meteor" + }, + { + "riddle": "Longer than a decade and shorter than a milennium", + "answers": [ + "century" + ], + "fullAnswer": "Century" + }, + { + "riddle": "Rolling on floor", + "answers": [ + "laughing" + ], + "fullAnswer": "Laughing" + }, + { + "riddle": "There are four of these, but everyone's favourite seems to be spades", + "answers": [ + "ace" + ], + "fullAnswer": "Ace" + }, + { + "riddle": "Rabbits do this to carrots and Jason Mraz does this to ears", + "answers": [ + "nibble" + ], + "fullAnswer": "Nibble" + }, + { + "riddle": "These minerals are vital to your health", + "answers": [ + "vitamin" + ], + "fullAnswer": "Vitamin" + }, + { + "riddle": "Commits friendly home invasions one night a year", + "answers": [ + "santa claus" + ], + "fullAnswer": "Santa claus" + }, + { + "riddle": "Treats said to be based on a shephero's staff", + "answers": [ + "candy cane" + ], + "fullAnswer": "Candy cane" + }, + { + "riddle": "Everyone claims to know a way to stop these involuntary contractions but none of them work", + "answers": [ + "hiccup" + ], + "fullAnswer": "Hiccup" + }, + { + "riddle": "Has 4 lucky leaves", + "answers": [ + "shamrock" + ], + "fullAnswer": "Shamrock" + }, + { + "riddle": "One of the best things you can hope for after whacking a ball with a stick", + "answers": [ + "home run" + ], + "fullAnswer": "Home run" + }, + { + "riddle": "They put the heat in pop tarts", + "answers": [ + "toaster" + ], + "fullAnswer": "Toaster" + }, + { + "riddle": "What has a ring, but no finger?", + "answers": [ + "telephone" + ], + "fullAnswer": "Telephone" + }, + { + "riddle": "What has four legs, but can't walk?", + "answers": [ + "table" + ], + "fullAnswer": "Table" + }, + { + "riddle": "What is higher without the head, than with it?", + "answers": [ + "pillow" + ], + "fullAnswer": "Pillow" + }, + { + "riddle": "What is harder to catch the faster you run?", + "answers": [ + "breath" + ], + "fullAnswer": "Breath" + }, + { + "riddle": "What is made of wood, but can't be sawed?", + "answers": [ + "sawdust" + ], + "fullAnswer": "Sawdust" + }, + { + "riddle": "What is a witch's favorite school subject?", + "answers": [ + "spelling" + ], + "fullAnswer": "Spelling" + }, + { + "riddle": "What is an aliens favourite sport?", + "answers": [ + "spaceball" + ], + "fullAnswer": "Spaceball" + }, + { + "riddle": "What is the saddest fruit?", + "answers": [ + "blueberry" + ], + "fullAnswer": "Blueberry" + }, + { + "riddle": "What is black and white and read all over?", + "answers": [ + "newspaper" + ], + "fullAnswer": "Newspaper" + }, + { + "riddle": "What is easy to get into, and hard to get out of?", + "answers": [ + "trouble" + ], + "fullAnswer": "Trouble" + }, + { + "riddle": "If two hours ago, it was as long after one o'clock in the afternoon as it was before one o'clock in the morning, what time would it be now?", + "answers": [ + "nine" + ], + "fullAnswer": "Nine" + }, + { + "riddle": "What types of words are these: Madam, Civic, Eye, Level?", + "answers": [ + "palindrome" + ], + "fullAnswer": "Palindrome" + }, + { + "riddle": "It is an insect, and the first part of its name is the name of another insect. What is it?", + "answers": [ + "beetle" + ], + "fullAnswer": "Beetle" + }, + { + "riddle": "What word of five letters has only one left when two letters are removed?", + "answers": [ + "stone" + ], + "fullAnswer": "Stone" + }, + { + "riddle": "How many 9's are there between 1 and 100?", + "answers": [ + "twenty" + ], + "fullAnswer": "Twenty" + }, + { + "riddle": "Which vehicle is spelled the same forwards and backwards?", + "answers": [ + "racecar" + ], + "fullAnswer": "Racecar" + }, + { + "riddle": "I am lighter than air, but a million men cannot lift me up, What am I?", + "answers": [ + "bubble" + ], + "fullAnswer": "Bubble" + }, + { + "riddle": "Five men were eating apples, a finished before B, but behind C. D finished before E, but behind B. What was the finishing order?", + "answers": [ + "cabde" + ], + "fullAnswer": "CABDE" + }, + { + "riddle": "David's father has three sons: Snap, Crackle, and ?", + "answers": [ + "david" + ], + "fullAnswer": "David" + }, + { + "riddle": "It is everything to someone, and nothing to everyone else. What is it?", + "answers": [ + "mind" + ], + "fullAnswer": "Mind" + }, + { + "riddle": "What has a mouth but can't chew?", + "answers": [ + "river" + ], + "fullAnswer": "River" + }, + { + "riddle": "If it is two hours later, then it will take half as much time till it's midnight as it would be if it were an hour later. What time is it?", + "answers": [ + "nine" + ], + "fullAnswer": "Nine" + }, + { + "riddle": "Forward I am heavy, backwards I am not. What am I?", + "answers": [ + "ton" + ], + "fullAnswer": "Ton" + }, + { + "riddle": "What object has keys that open no locks, space but no room, and you can enter but not go in?", + "answers": [ + "keyboard" + ], + "fullAnswer": "Keyboard" + } ] diff --git a/config/default.js b/config/default.js index 5b0177d..d8fd326 100755 --- a/config/default.js +++ b/config/default.js @@ -57,6 +57,10 @@ module.exports = { length: 9, timeout: 60, }, + riddle: { + timeout: 10000, + score: false, + }, dice: { maxRolls: 10, maxFaces: 1000, diff --git a/src/games/riddle.js b/src/games/riddle.js index 1544a52..3cae7f6 100644 --- a/src/games/riddle.js +++ b/src/games/riddle.js @@ -1,12 +1,59 @@ 'use strict'; +const config = require('config'); +const crypto = require('crypto'); +const timers = require('timers/promises'); + const riddles = require('../../assets/riddles.json'); +const style = require('../utils/style'); const open = new Map(); -function onCommand(args, context) { +const emojis = ['😆', '🤣', '😂', '😅', '🤪', '😛', '😝', '🙃', '🥲', '🤭', '😏', '🥴', '💀', '🤦']; + +async function onCommand(args, context) { + if (open.has(context.room.id)) { + context.sendMessage(open.get(context.room.id).riddle, context.room.id); + return; + } + + const riddle = riddles[crypto.randomInt(0, riddles.length)]; + const ac = new AbortController(); // eslint-disable-line no-undef + + open.set(context.room.id, { ...riddle, ac }); + + context.sendMessage(riddle.riddle, context.room.id); + context.logger.info(`Riddle asked "${riddle.riddle}" with answer: ${riddle.answers[0]}`); + + try { + await timers.setTimeout(config.riddle.timeout, null, { signal: ac.signal }); + + open.delete(context.room.id); + context.sendMessage(`No one guessed the riddle: ${style.bold(riddle.fullAnswer)}! ${emojis[crypto.randomInt(0, emojis.length)]}`, context.room.id); + } catch (error) { + // timer aborted because someone guessed the answer + } +} + +function onMessage(message, context) { + const riddle = open.get(context.room?.id); + + if (riddle && riddle.answers.some((answer) => new RegExp(`\\b${answer}s?\\b`, 'i').test(message.body))) { + riddle.ac.abort(); + open.delete(context.room.id); + + if (config.riddle.score) { + context.setPoints(context.user, 1); + context.sendMessage(`${style.bold(style.yellow(riddle.fullAnswer))} is the right answer! ${context.user.prefixedUsername} gets a point.`, context.room.id); + + return; + } + + context.sendMessage(`${style.bold(riddle.fullAnswer)} is the right answer!`, context.room.id); + } } module.exports = { onCommand, + onMessage, }; diff --git a/src/play.js b/src/play.js index 111d150..9dee4f3 100755 --- a/src/play.js +++ b/src/play.js @@ -61,7 +61,7 @@ function getPoints(game, rawUsername, { user, room, command }) { ? Object.entries(gamePoints || {}).find(([identifier]) => identifier.split(':')[1] === username)?.[1] : gamePoints?.[`${user?.id}:${user?.username}`]; - game.sendMessage(`${username ? `${style.bold(username)} has` : 'You have'} scored ${style.bold(userPoints || 0)} points in ${game.name}, ${config.usernamePrefix}${user.username}`, room.id); + game.sendMessage(`${username ? `${style.bold(username)} has` : 'You have'} scored ${style.bold(userPoints || 'no')} points in ${game.name}, ${config.usernamePrefix}${user.username}`, room.id); } function getLeaderboard(game, { user, room, command }) {