Struggling to use eval & urlfetch together?

Asked Apr 17, 2023·5 replies·Last activity 3 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.
$(urlfetch (my api url)/nightbot/multiline?raw=true&msgs=$(eval const names = '$(querystring)'.split(' '); const channels = names.map(n => $(twitch ${n} "{{url}} - [{{game}}]")).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = [initText, channels].join(''); msgs))

Can someone help me find out whats wrong here? Its posting everything in this block above ^ instead of the api response, im intending on.

5 replies

Hey @Topaz Kangaroo!

I'd suggest using an alias command, I believe Nightbot calls the $(urlfetch) before resolving the $(eval), so something like this should solve your problem:

!addcom !commandName -a=_commandName $(eval const names = decodeURIComponent('$(querystring)').split(' '); const channels = names.map(n => $(twitch ${n} "{{url}} - [{{game}}]")).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = [initText, channels].join(''); msgs)
!addcom _commandName $(urlfetch https://yourApi.url/nightbot/multiline?raw=true&msgs=$(querystring))

I'm getting a

txt
missing ) after argument list

!multiso

txt
$(eval const names = decodeURIComponent('$(querystring)').split(' '); const channels = names.map(n => $(twitch ${n} "{{url}} - [{{game}}]")).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = [initText, channels].join(''); msgs)

!_multiso_api

txt
$(urlfetch https://api.itsjusttriz.com/nightbot/multiline?raw=true&msgs=$(querystring))

Of course!
I barely checked your code, but there's an important mistake here:
names.map(n => $(twitch ${n} "{{url}} - [{{game}}]"))
Can you see it?

Here's the fix, I highlighted the important parts:

But even that isn't enough, and that's because the `$(twitch)` variable is resolved before the `.map()` is called, I wonder if the following would fix it completely:
!addcom !multiso -a=_commandName $(eval const names = decodeURIComponent('$(querystring)').split(' '); const channels = names.map(n => `(twitch ${n} "{{url}} - [{{game}}]")`); const twitch = channels.map(c => '$' + c).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = `${initText} ${channels}`; msgs)
And in the alias command, try with `$(querystring)`, but if it doesn't work, try with `$(query)`.

Now this:

I need it to resolve the mapped $(twitch) before calling $(urlfetch)

deee720f96e297f975c92c06671cfca9.png

Damn, so close! I'm not sure I have a solution to offer anymore...

I made a similar command before, but I don't have the game listed, only the URL, which can be done simply by concatenating twitch.tv/ and the username, so I don't rely on the $(twitch) variable.
I wonder if I faced the same problem as you and forgot, since it's been years at this point.

Didn't find your answer? The community is on Discord.

Ask on Discord