Riddle Command for Nightbot

Hey @hoodlumkira!

Before we start, your JSON file presents many errors—mostly missing commas, that’s the reason why you get the error, so please copy/paste the correction I made of it (expires in 2 weeks).
Also, riddle #15 was missing, so you have 30 riddles, not 31.

Then @potatoeaterlove if I may, I recommend using the following syntax to navigate through a JSON if you’re going to have a dynamic variable to reach an element: RiddleList[`Riddle${var}`].Riddle

Finally, I rewrote the command by simplifying it a bit, and making sure that “answer” would evaluate to correct as well as “an answer” or “a very long answer” as it wasn’t the case.

RiddleList=$(urlfetch json https://pastebin.com/raw/XXXXXXXX);
q=`$(query)`.split(` `);
if(q.length>=1&&!isNaN(q[0])&&q[0]>0&&q[0]<=30){
	if(q.length==1){
		RiddleList[`Riddle${q}`].Riddle;}
	else{
		n=q.shift();
		RiddleList.[`Riddle${n}`].Answer.toLowerCase().includes(q.join(` `).toLowerCase())?`Correct!!!`:`Wrong :/`;}
}
else{`Please choose a riddle (1 → 30). To submit an answer, specify the riddle number, then your answer.`}

Here’s the command for a quick copy/paste, make sure to replace XXXXXXXX with your paste ID:

$(eval RiddleList=$(urlfetch json https://pastebin.com/raw/XXXXXXXX);q=`$(query)`.split(` `);if(q.length>=1&&!isNaN(q[0])&&q[0]>0&&q[0]<=30){if(q.length==1){RiddleList[`Riddle${q}`].Riddle;}else{n=q.shift();RiddleList[`Riddle${n}`].Answer.toLowerCase().includes(q.join(` `).toLowerCase())?`Correct!!!`:`Wrong :/`;}}else{`Please choose a riddle (1 → 30). To submit an answer, specify the riddle number, then your answer.`})
1 Like