Riddle Command for Nightbot

Hello,

I’m trying to create a !Riddle based on a custom list of Riddles I create. I will put them in Pastebin. I’ve seen someone has done this, and I was curious how they are able to get it to use 2 commands (!riddle and !answer) to pull the correct info from the same file. I guess I don’t understand the necessary formatting for the file. Any Help?

So you’ll just want to format it like this:

RiddleList={
"Riddle1":{"Riddle":"RIDDLE_1_HERE","Answer":"ANSWER_1_HERE"},
"Riddle2":{"Riddle":"RIDDLE_2_HERE","Answer":"ANSWER_2_HERE"},
"Riddlex":{"Riddle":"RIDDLE_x_HERE","Answer":"ANSWER_x_HERE"}
}

If you need further help with the command itself let me know.

Hey man i was wondering how you would go about coding something like this as i don’t have much knowledge in how to programming nightbot and things like this using two separate command and im still trying to learn as much as i can :sweat_smile:

Wel firstly have to made a pastebin of all the riddles you want?

yes i have got one set up

it isnt 100% complete but i hope its set up right

Well you don’t need to have “Riddlex” it should be Riddle3 that was just and example I posted earlier. Also for the answer to the last one it should just be two. As long answers aren’t hard to guess

Alright i have changed that now to riddle3 and two

Here’s the command:

$(eval RiddleList=$(urlfetch json https://pastebin.com/raw/Xw5kc5E8);`$(3)`!=`null`?`To many arguments given.`:`$(1)`==`null`?`Please choose a riddle 1-31 and type the answer after it.`:`$(2)`==`null`&&parseInt(`$(1)`)<=31&&parseInt(`$(1)`)>=1?RiddleList.Riddle$(1).Riddle:parseInt(`$(1)`)<1||parseInt(`$(1)`)>31?`Sorry riddle “$(1)” does not exist.`:`$(2)`.toLowerCase()==RiddleList.Riddle$(1).Answer.toLowerCase()?`Correct!!!`:`Wrong :/`)

Add this trough the dashboard it won’t send through chat.
Also get rid of the “RiddleList=” at the very begging (In the pastebin)

Btw the last answer is mistyped. And riddle 10 is blank.

Thanks man ive corrected those two riddles, removed the “riddlelist=” and i added it through nightbot dashboard. Though it comes up with unexpected string if i leave the “{}” around all the riddles in pastebin but if i remove them it comes up with "unexpected token ‘:’ "

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

Thanks heaps Potatoeaterlove and Emily

it works now i think it was mainly an issue with the way the pastebin was set up, but it works perfectly now. I thank you guys for your help :grin:

1 Like

Ahh… this topic still in debate … bro me too use riddles like games in my stream recommend you to use this.

JUST COPY PASTE THESE LINES IN YOUR STREAM CHAT. It will work.

FOR RIDDLE QUESTION

!addcom -cd=5 -ul=everyone !riddle [ $(user) ] → $(urlfetch json https://nightbot-clip-command.herokuapp.com/riddle)

FOR RIDDLE ANSWER

!addcom -cd=5 -ul=moderator !answer [ $(user) ] → $(urlfetch json https://nightbot-clip-command.herokuapp.com/riddle?q=answer)

Note: if you called !answer without using !riddle it will raise an error.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.