AirGee
August 4, 2021, 9:07pm
1
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!
Emily
August 5, 2021, 8:43am
2
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
AirGee
August 5, 2021, 1:57pm
3
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
2 Likes
Emily
August 5, 2021, 8:58pm
4
Glad to know my explanation was good enough!
2 Likes
system
Closed
August 19, 2021, 8:58pm
5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.