Help with nested eval

Trying to use an $(eval) command to randomly pick a URL from a pastebin to use as the URL for another $(eval) command. I thought the limit was 2 evals in a nest, so I figured this would work, but getting ‘Unexpected identifier’.

$(eval const rss = $(urlfetch json $(eval a=$(urlfetch json"#");a[Math.floor(Math.random() *a.length)])); rss.items[0].description;)

Basic idea is to just have a list of rss2json links with different news outlets so the command randomly outputs news descriptions. There’s probably a better way of doing this, but I’m still not sure why this doesn’t work.

Hi @Hoopy Let me advice my solution.

Saw your Pastebin there is one minor issue, leading " and trailing " by this date (2040 IST) which might not give what you want.

I advice you to make an array something like:-


Why array? To prevent any such .split() function.

You need to make a command which return link which then can be used by alias command.

const links = $(urlfetch json PASTEBIN_LINK);  /* fetch the links */
let link = links[Math.floor(Math.random() * links.length)];  /* get any random link */
link;  /* return the link, which can be used by it's alias command */
let data = $(urlfetch json $(query));  /* IIRC the ``link`` from parent command will be in $(query) */

I haven’t tested this approach, but this more likely to work. Commands are as follows:

!addcom -cd=5 -a=__cmdName !cmdName $(eval const links=$(urlfetch json PASTEBIN_LINK); let link = links[Math.floor(Math.random() * links.length)]; link;)
!addcom -cd=5 __cmdName $(eval let data = $(urlfetch json $(query)); data.items[0].title;)

If the command doesn’t work, please feel free to ask.

Ritik Ranjan

Thank you very much. I was using .split() because I’ve used it before for other commands and figured it’d be fine here.

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