If/Else !hug command

Hey!

I am fairly new to Nightbot and Javascript in general, but I am wondering if it would be possible to create a !hug chat command that if executed by myself would always hug one specific nickname, and if executed by anyone else in the chat, the command would choose a random person in the chat.

Thank you for help in advance!

@suur

This script below outputs a specific username if the command user is “Suur” and outputs a random username otherwise. Replace USER_TO_HUG with the specific username you want.

!addcom -cd=5 !hug $(eval u=`$(user)`;if(u==`Suur`){`${u} hugged USER_TO_HUG`;}else{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);`${u} hugged `+(b[Math.floor(Math.random()*b.length)]||`nobody. It's lonely in here.`);}catch(e){`Error: ${e.message}`.slice(0,400);}})

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