Trigger an alias within a command upon condition?

Hello!
Sorry not quite sure how to ask this question and compress it into a title lol.

Is it possible to make it so a command uses an alias, but only trigger that alias when a condition is met?
Say that your command is looking for a specific word in a user’s query, let’s say !test alias… If the person types !test -random word here-, then nothing happens (or X random action happens), but if they type !test alias, the command will actually trigger the alias, which in turn triggers whatever command the alias is pointing to… let’s say -a=!positive.

Thanks in advance for making sense of the question…

The actual idea is for the command to trigger a random response generator I have already prepared, but only when specific words are used along with !test. I know that Nightbot only allows up to 500 characters in a command, so the idea is to have that part of the code call for a command that already does this action, leaving room to program something else for a different set of words. But of course I don’t want the random response generator to trigger every time… only when it has to.

1 Like

I don’t believe it is possible to do exactly what you describe. But it would be possible for your !positive command to only generate a random response if a simple test, such as $(query) being empty, is true. This way, the majority of the logic (testing the user input for your specific cases) is contained to the !test command.

In order for Nightbot to not send a message when the conditions are not met, you can make the !positive command return a single space.

Another method you could use to get around the 500 character limit is to use a JavaScript compressor, such as this one: https://jscompress.com.

Hmm… How would “!positive” know if I said one of the correct words without actually typing !positive though?
Is it not possible to do a -a=!positive after a condition because the alias would trigger immediately? because if so I was thinking maybe doing something like:
condition ? '-a' + '=!positive' : ''

… could maybe work? So the alias doesn’t get triggered immediately but rather gets put together if the condition is true

Not sure how to use that compressor with Nightbot commands D:

It sounds like you want one command to have multiple aliases, which is not possible. If this is what you are talking about, it might be better for you to just ditch the !test command altogether and make separate commands that can be called individually.

If I misunderstood you, and you actually just want one command to trigger one alias conditionally, here is example code that will do that:

!commands add !test -a=!positive $(eval words = [“word1”, “word2”, “word3”]; response = “”; for(i = 0; i < words.length; i++){if (`$(query)`.indexOf(words[i]) != -1){response = “p”}} response)

!commands add !positive -ul=moderator $(eval if (`$(query)` === “p”){“random response”} else {" "})

Yes that’s right! So basically you would have 2 sets of defined words. If you say any defined word from the first set, it would trigger a response from the logic within !test. If you say any defined word from the second set, the command would trigger the alias (-a=!positive), which in turn has a “random response” code in it, picking a random response from a second file.
My idea to have the second set be used in an alias is so I can have something similar to an 8ball command, but without having to include the 8ball logic into !test to save space. If any of that makes sense.

Will that example make it so !positive is only triggered if word 1, 2 or 3 is said along with !test?

Yes. You just need to add your own random response logic in place of "random response"

1 Like

Thank you very much :D!

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