Nightbot reacting to a sentence

Asked Aug 4, 2021·3 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.

Hi Guys,

with your help in several threads I created a reply for Nightbot with this command:
!addcom FIRST_WORD_OF_THE_SENTENCE $(eval $(query).includes(REST_OF_THE_SENTENCE)?RESPONSE: ; )

My question is: is it possible to add more options for REST_OF_THE_SENTENCE? And if yes, how?

Thanks!

3 replies

Hey @Swanky Seal!

Yes you can, but in that case we'll modify the command a bit to be a bit more efficient, here's how to do it for 2 sentences:

!addcom FIRST_WORD $(eval q=`$(query)`.toLowerCase(); q.includes(`REST_OF_THE_FIRST_SENTENCE_IN_LOWER_CASE`)?`YOUR_FIRST_RESPONSE`:q.includes(`REST_OF_THE_SECOND_SENTENCE_IN_LOWER_CASE`)?`YOUR_SECOND_RESPONSE`:` `)

Or if the response is the same in either case:

!addcom FIRST_WORD $(eval q=`$(query)`.toLowerCase(); q.includes(`REST_OF_THE_FIRST_SENTENCE_IN_LOWER_CASE`) || q.includes(`REST_OF_THE_SECOND_SENTENCE_IN_LOWER_CASE`)?`YOUR_RESPONSE`:` `)

I'm using the ternary operator ?: here, it replaces if/else:

condition ? if truthy : if falsy

So if you want to chain these you put a new condition to test if the first condition is falsy:

condition ? if truthy : condition ? if truthy : condition ? if truthy : if falsy

Oh my gosh Emily,

such a good explanation i tried it even with 3 variants and it worked with the first attempt.

Thank you very much, really much appreciated 🙂

Glad to know my explanation was good enough!