2022 visit: it’s fun seeing where I started, now JavaScript is my best friend.
Hello!
Is it me or a do while loop will result in a “script execution timed out after 1000ms” if the loop doesn’t end fast enough?
For example, I made a command that picks someone at random in the chat, but if it’s one particular person it picks someone else, so the loop looks like this:
The $(urlfetch) will only ever evaluate one time when you use the command. If the $(urlfetch) evaluates to the particular username given in the do/while loop’s condition, you will be assigning that particular username string to the variable v over and over until you hit the 1000ms execution time limit.
That said, there does exist this remote resource that provides the list of viewer names in a channel. This script gathers the usernames into an array and filters out particular usernames, then outputs one of the usernames at random. Replace USER_TO_EXCLUDE with the particular username you want to filter out:
try{a=JSON.parse(`$(urlfetch json http://tmi.twitch.tv/group/user/$(channel)/chatters)`).chatters;b=a.broadcaster.concat(a.vips,a.moderators,a.staff,a.admins,a.global_mods,a.viewers).filter(c=>![`$(user)`,`Nightbot`].some(d=>c.toLowerCase()==d.toLowerCase()));b.length>0?`$(user) interaction ${b[Math.floor(Math.random()*b.length)]}!`:`It's lonely in here...`;}catch(e){`Error: ${e.message}`.slice(0,400);}
Note that this filter can remove multiple usernames if you so desire. Just enter them into the array of usernames to exclude, bounded by backticks `` and separated by commas.