I'm a big pepega

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)

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.

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