Nightbot reacting to a sentence

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!

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

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 :slight_smile:

2 Likes

Glad to know my explanation was good enough!

2 Likes

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