Get a random user from chat (PASTEBIN)

Hi,

I’m having trouble trying to get a Nightbot variable from a Pastebin URL. The goal of the command is that Nightbot will random grab one entry from the list of sentences and within that sentence it will grab a random users @.
Here is the pastebin it references:
https://pastebin.com/raw/2ULccb6v
and here is the output:
has buttered $(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel)) 's buns.

You can’t define nightbot variables like that define it outside the urlfetch then replace it afterwards.

1 Like

how do I define the URL fetch outside? I saw example of where people were replacing @(user) but the url seems like it might be different.

how do I define the URLfetch outside?

Here’s example:

$(eval a=`$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel))`;b=$(urlfetch json pastebin_link).split(`Splitting_Character`);b[Math.floor(Math.random()*b.length)].replace(`USER`,a))

So instead of the urlfetch in the command have it be USER all caps or any word that you don’t use anywhere else.

If you need me to elaborate more just say.

1 Like

Hey @criminateee!

There are a lot of topics that cover this already, here’s one, please use the search bar before opening a new ticket.

2 Likes

When I try this:
!commands add !butter $(eval a=$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel));b=$(urlfetch json pastebin_link).split(Splitting_Character);b[Math.floor(Math.random()*b.length)].replace(USER,a)) $(user) $(eval a="$(urlfetch json https://pastebin.com/raw/2ULccb6v)%22.split(%22;%22);a[Math.floor(Math.random()*a.length)])
the output is:
Unexpected identifier Criminateee Invalid or unexpected token

Well I presumed you knew how to fill in the blanks in the command. Like replacing pastebin_link and splitting_character the code should work also why is there a second eval? You can also check out what @Emily said if you need it to all be pre made for you.

2 Likes

Hi Emily,

I tried to implement what’s in this thread but to no success. Where am I going wrong?

!commands add !butter $(eval r=$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel)); u=$(user); $(urlfetch https://pastebin.com/raw/2ULccb6v))

image

So, I assume in your Pastebin are the different possible responses Nightbot can pick from, first you’ll want to fix those a bit:

`${u} has spread a load of butter on ${r}.`
`${u} has buttered ${r}'s buns.`
`${u} has let ${r} hold their stick of butter!`

Now, nowhere in your code you make Nightbot pick the response, here’s how I’d do it:
(this is the code that goes in your Pastebin)

const responses = [`${u} has spread a load of butter on ${r}.`, 
  `${u} has buttered ${r}'s buns.`,
  `${u} has let ${r} hold their stick of butter!`];

responses[Math.floor(Math.random() * responses.length)];

And finally, we need to fix the rest of your code, your text variables must be marked as such:

!addcom !butter $(eval r='$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel))'; u='$(user)'; $(urlfetch json https://pastebin.com/raw/2ULccb6v))
3 Likes

Thank you! How would I add a filter to it?

Filter out users from the randomly picked ones? You should have mentioned it sooner, also, you could have found the solution by searching for random user filter in the forums:

Basically, replace r='$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel))'; with:

r=$(urlfetch json http://tmi.twitch.tv/group/user/$(channel)/chatters).chatters;a=r.broadcaster.concat(r.vips,r.moderators,r.staff,r.admins,r.global_mods,r.viewers).filter(n=>![`$(user)`,"Nightbot","UnwantedName3"].some(o=>n.toLowerCase()==o.toLowerCase()));a.length?r=a[Math.floor(Math.random()*a.length)]:r="No chatters";

and don’t forget to replace the fields [$(user),"Nightbot","UnwantedName3"] by what you want to filter out.

3 Likes

It says that c is not defined? Is that because of c.vips, c.moderators, c.staff, etc?

Ah, sorry, I modified it in a hurry, I had a meeting, and I missed some stuff, I updated the code, it should work fine now.

To answer your second question: yes.

1 Like

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