syntax to urlfetch a variable

Asked Apr 10, 2021·4 replies·Last activity 5 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.

Please if anyone knows is it possible to use a url as a variable with $(urlfetch), specifically, the url for getting a random user, like:

$(eval url1=https://2g.be/twitch/randomviewer.php?channel=$(channel); $(urlfetch url1)

I want to do this so that I can call urlfetch 4 times in a single command without using the full length url each time - to stay below the max character limit in Twitch chat when adding the command.

4 replies

Hiya, what kind of command would you like to make? Think there is better solutions to get multiple users from your viewerlist if you directly get them from Twitch with one request, instead of calling this API multiple times.

Howdy, like, a twist on the game of: one friend names 3 celebrities or other friends then a second friend hypothetically decides which one they'd marry, which one they'd kill, and which one they'd ...sleep with.

so like: "random user" wants to f "random user", marry "random user", kill "random user"***

current version of the command looks like this – which works, but I wanted to make a more complicated version and then ran into the character limit issues:

!editcom !FMK @$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel)) wants to F**K @$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel)), marry @$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel)), and KILL @$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))

Yes, please though, if there's a way to get multiple users from the viewerlist with one request please let me know (I should probably have tried researching that angle first).

Ok thanks for clarifying, let me just yoink some of Emily's code from this recent topic.

You will need to post some code to pastebin, since the text is to long for a Nightbot command.
Pastebin code, where you can edit the responses:

js
try
{
c = JSON.parse(r).chatters;
a = c.vips.concat(c.moderators,c.staff,c.admins,c.global_mods,c.viewers)
.map((a) => ({sort: Math.random(), value: a}))
.sort((a, b) => a.sort - b.sort)
.map((a) => a.value);
if(a.length >= 3)
{
`${a[0]} wants to f*** ${a[1]}, marry ${a[2]}, kill ${a[3]}`
}
else
{
`Not enough chatters`
}
}
catch(e)
{
`Couldn't fetch the list of chatters: ${e}: ${r}`.slice(0,400)
}

Then add a command to Nightbot like this, where you replace the XXXX pastebin ID:

!commands add !something $(eval r=`$(urlfetch json http://tmi.twitch.tv/group/user/$(channel)/chatters)`; $(urlfetch json https://pastebin.com/raw/XXXX))

Not sure how big the channel is, because I dont know if it will work fluenty in big channels, but try it out. :)