NightDev Community Forums

Use of eval inside urlfetch inside eval results in error

I’d like to fetch a specific url based on a user’s name and provided query and work with the returned json. I need an eval in a urlfetch in an eval which gives me Error Connecting To Remote Server

mimimal example that does not work:

$(eval const resp = $(urlfetch $(eval "http://(www).$(eval "perdu").com/")); resp)

while the following does:

$(urlfetch $(eval “http://(www).$(eval “perdu”).com/”))

(can’t include links)

There has been a post from 2017 where this was a proposed solution, yet it no longer works:
[Custom API] Using a URL from a variable/constant in urlfetch

Neither does the wiki example from the urlfetch doc.

Hey @Fl_GUI!

It doesn’t work because you’re nesting too many $(eval), Nightbot has a limit of 2 levels regarding nesting, as said in the 2017 post you mentioned.

If you need more than two levels of nesting, you’ll have to make !test an alias to another command. !test can pass data to the alias, and the alias can access it with the query variable.

Also, I’m not sure I understand what you’re trying to do, so I can’t help. It’d be nice if we had more details, if you can’t include the links then put clear placeholders, for example to a JSON on Pastebin that isn’t the one you’ll use, but which follows the same pattern, and the exact JS of the command you wrote.
I think the answer from 2017 can still help you, because I think that what you posted can be simplified by removing the second and/or third $(eval), but that’s because I don’t have the full context.

If explaining what your trying to do is too hard in English, do it in French, as I think it’s your mother tongue, which is mine as well.

Thank you very much for your reply, I got it working using an alias.

I didn’t include my command because I don’t want to waste anyone’s time more than I already am (and I enjoy writing them myself).

If you are curious:

$(urlfetch json $(eval const qr = ‘$(querystring)’ || “alegendarybagel” ; const name = qr === “me” ? “$(user)” : qr ; https://www.speedrun.com/api/v1/users/${name}/personal-bests))

with an alias to

$(eval resp = $(query); const time = resp.data[0].run.times.primary_t ; const sec = time % 60 ; const min = (time - sec)/60 ; const s = [“th”,“st”,“nd”,“rd”] ; const v = resp.data[0].place % 100 ; ${min}:${sec < 10 ? '0' : ''}${sec} (${resp.data[0].place + (s[(v-20)%10]||s[v]||s[0])} place))

is what I got working.

This fetches the pb of a default username, specified username or the user itself from the speedrun.com api.
I’m probably doing stupid/unnecessary things 'cuz I’m not familiar with the speedrun.com and nightbot api. In fact, I just found out that you can fetch runs and filter on user and game in the url.

French is close, but I was just tired. hope this message is better.

Nice, I’m glad you got it working!
But yeah, including your own code can often help us help you, haha! We don’t mind reading, in fact we prefer if people share as much details as possible to be able to give the best support possible.

1 Like