[Custom API] Send variables to second urlfetch

Asked Dec 24, 2020·1 reply·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I have the following command which reads a timestamp from the first urlfetch and compares it to a set time (30minute duration) and then posts ${m} mins and ${s} secs remaining into chat. I need to push the ${m} and ${s} out to a second urlfetch but I cannot get it to work. Here is the code I have right now..

$(eval q=$(urlfetch http://twitch.center/customapi/quote?token=1stTOKEN&data=1&no_id=1),m=q.match(/^(.+)\|\d+$/),m?(t=parseInt((new Date(m[1])-new Date)/1e3),t<=0?"Complete.":(m=Math.floor(t/60)%60,s=t%60,(m>0? ${m} min:"")+(s>0? ${s} sec $(urlfetch https://twitch.center/customapi/editquote?token=2ndTOKEN&data=1&no_id=1 ${m} min ${s} sec):""))):q==""?"":"")

1 reply

Nightbot variables evaluate inner to outer, so the urlfetch in the JS string is already evaluated before the JS is run by the eval. What you can do is set this command as an alias of another command which runs a urlfetch on the input to add the timestamp to the list then outputs the timestamp.