Using javascript with Eval

Heya

I’m trying to rewrite a command. The command fetches from warp.world API.
Due to message length limitations on YouTube, the command does not work.

Are there any limitations to the JS one can use with $(eval)?

Here’s what I’ve been trying to do:

var str = $(urlfetch Warp World - The Future of Streaming etc.);
if (($(provider) == ‘youtube’))
{ str = str.substr(1,201-3) + “…”; }
return str;

And then I wrap it up like $(eval above code).
I’ve tried some different implementations of the same thing, but the only error popping out of NightBot when I try the command is “right-hand side of ‘instanceof’ is not an object”

Can I perhaps not use $(provider) or $(urlfetch) within an $(eval)?

Thanks

1 Like

If it’s a json API, you can specify that it’s json to grab the whole payload.

$(urlfetch json http://some.json/api)
2 Likes

Warp World seems to use PHP. Returns plaintext.

The problem isn’t that NightBot cannot get ahold of the entire payload from Warp World.
Rather it’s that the payload needs to shortened so that it’ll fit YouTube’s length requirements.

I’m trying to do that using the $(eval) variable within a Nightbot command.

Usually, we’ve been using a regular $(urlfetch), like the one in the OP.
That has been working great over at Twitch though, which is why I’m trying to use the $(provider) variable…

Ah, you’re trying to trim the output, not the input.

You want something like

$(eval `$(urlfetch http://warp.world/bot/2 etc.)`.substr(0, `$(provider)` === 'youtube' ? 200 : 400))
1 Like

Yeah, precizzle dizzle.

So, if I understand correctly, to make use of Nightbot variables within $(eval), I’ll just have to wrap them backticks, right?

Thanks for the help. I’ll it a go next time we’re streaming. :slight_smile:

Template literals are used because they are infrequently used by people. If the API being fetched outputs a backtick it will break.

Thanks again, @night. It worked great. :kissing_heart:

Seems to me as if Nightbot won’t let me make en $(eval) with more than one JS statement, but I still managed to get the kind of output I wanted, so it’s no biggie.
Feel free to correct me on that though.

I know there are some other streamers on YouTube that use Nightbot and warp.world, who can’t get their !queue going, so I’ll just drop this here and hope they find it when searching :horse:

I suppose maybe Youtube “superchat” would allow for longer message length… I’ll update this post in case I find that to be the case

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