If/Else based on user input

Asked Jul 15, 2020·3 replies·Last activity 6 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.

Is there a (resonable) way to get Nightbot to respond (without writing an external JS) to do one action IF there is input and another if not? For example: !cookie $(user) gave $(touser) a cookie IF there is input, otherwise call the 2g.be randomviewer return? So, if I type !cookie USERNAME it returns "ToeKneeTM gave USERNAME a cookie" but if I JUST type !cookie, I can fetch a random viewer using the 2g.be randomviewer call and return "ToeKneeTM gave RANDOMVIEWER a cookie"? Thank you in advance!

3 replies

Try this

!addcom -cd=5 !cookie $(user) gave $(eval a=decodeURIComponent(`$(querystring)`);b=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;a?a.slice(0,400):(b!=`Empty viewer list`?b:`no one`)) a cookie

You. Are. Awesome. Can I share this? How can I give you credit? Social, Stream or Youtube link? I'm the same name pretty much everywhere.

Feel free to share this code! And there's no need at all to credit me, though at the most you can perhaps give me a little shoutout if anyone asks where you got the code.