Custom Greeting

Hi folks,

I am trying to make nightbot respond to good morning, good afternoon, good evening and good night.

Would the following work:

$(eval if ($(querystring $(1)).toLowerCase().includes(morning)) {Response:smile: Good morning $(user)!} else if (`$(querystring $(1))`.toLowerCase().includes(`afternoon`)) {`Response`😄 Good afternoon $(user)!} else if ($(querystring $(1)).toLowerCase().includes(evening)) {Response:smile: Good evening $(user)!} else if (`$(querystring $(1))`.toLowerCase().includes(`night`)) {`Response`😄 sweet dreams $(user)!}

Also, I exceed the character limit using the web interface so should I use !addcom for this?

Thanks for your help!

I got the following to work due to youtube’s character limit:

$(eval $(querystring $(1)).toLowerCase().includes(morning)||querystring $(1)).toLowerCase().includes(afternoon)||querystring $(1)).toLowerCase().includes(evening)?:smile: Hey $(user)!: )

Hey @yProjekt!

Very happy you got it to work, however, allow me to show you a more compact way to do it:

!addcom good $(eval q = `$(1)`.toLowerCase().replace(/[^a-z]/g, ''); q === 'night' ? '😄 sweet dreams $(user)!' : ['morning', 'afternoon', 'evening'].includes(q) ? `😄 good ${q} $(user)!` : ' ';)
1 Like

Really appreciate your help! I will give this a try.

This doesn’t work unfortunately.

Nightbot just gives a blank output.

This is my bad, I misplaced a character in my code: /^[a-z]/ instead of /[^a-z]/:sweat_smile:
I fixed the code above, it should work as expected now.

However, you shouldn’t get empty responses when the message doesn’t match any valid inputs, I suspect this might be a difference between Twitch and YouTube: Twitch doesn’t accept empty messages (made of only spaces), maybe YouTube does when it comes from their API?

I suggest testing the command as is with a sentence like “good game.”
If Nightbot responds with an empty message you can try removing the space between the last two single quote marks: ' ';)'';)
And although it usually produces error, I hope it’ll work because there’s no other solution.

1 Like

This works great!

Thank you so much :grin:

1 Like

Quick question, did you have to remove the space or not?

I did not as removing it gave an error on YouTube.

1 Like

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