Nightbot reacting to a sentence

Hey @AirGee!

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
2 Likes