I’m looking to utilize the custom quote API in order to create a method of community writing.
In this situation, someone would use a !addword command to start a sentence, for instance, “the”, then someone else could add to that quote like “!addword cat” making the current quote now be “the cat” and continue from there.
With my basic level understanding of Javscript, I’m having a hard time getting the API to accept a variable stated in the eval command, within the URL fetch.
Inner Nightbot variables always resolve before the outer variables. The $(urlfetch)'s do not “know” that they are nested within an $(eval); thus with this command setup you are literally sending the letter “y” as the data parameter to the quote API.
This command setup should accomplish what you need. Replace PUBLIC_TOKEN with your public token (8 characters long) and PRIVATE_TOKEN with your private token (16 characters long).
!addcom -cd=5 !addword $(eval z=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=~W~$(querystring))`;a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`.split(`~W~`).filter(b=>b!=``).join(` `).slice(0,400);a&&a!=`There are no quotes added`?a:`There are no phrases added yet...`)
I’ve also set up a command !resetword (mod-only) to clear the phrases. Replace PRIVATE_TOKEN with your private token.
!addcom -ul=mod !resetword $(eval `$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)`==`All entries have been deleted`?`$(user) has reset the word!`:`Try again...`)