I'm a big pepega

Asked Jan 26, 2020·3 replies·Last activity 6 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.

Hi, I'm trying to do a command with the custom api quote to add or remove a number but I'm freaking rusty in js, I did this

$(eval
var a = new Number($(urlfetch https://twitch.center/customapi/quote?token=TOKEN&data=1&no_id=1)),
b = new Number($(2));
if ($(1) == add) {
a += b;
new String($(urlfetch https://twitch.center/customapi/editquote?token=TOKEN&data=1 ${a}));
} else if ($(1) == remove) {
a -= b;
new String($(urlfetch https://twitch.center/customapi/editquote?token=TOKEN&data=1 ${a}));
} else {
PEPEGA;
})

It do edit the quote but the quote is ${a} after, I can't do interpolation I'm going crazy

(I know the code is probably real ugly)

3 replies

I don't know exactly what you're trying to do here but I'm still certain this doesn't work -- the $(urlfetch) variables are resolved before any of the $(eval) code is run. So this command will run $(urlfetch) three times, insert the response into the javascript, and then run the resulting $(eval). Since your ${a} is inside your $(urlfetch) it never gets interpreted.

Since Nightbot works like this you cannot do anything with urlfetch in eval -- you can only use eval to do something with the result of a urlfetch after the fact.

I'm trying to store a number with the API and add or remove
specified amount like "!test add 1". It's my first time touching nightbot as you probably can see

Like I said the $(urlfetch) variables are resolved before any of the code is run.

So you cannot do what you want to do this way. If you want to change a number in a customapi you have to do it on the server side.