Passing an IF to a command via !editcom

Hello!

I was wondering if anyone has any clue how could I get this to work properly:


!addcom !setstream -a=!editcom !nextstream $(eval x="$"+"(countdown $(query) US/Eastern)"; if (x.match(/ago/g)) {"User should be 🔴Live! (If not, stay tuned!)"} else {"🔴 The next stream is planned in "+x})


Basically I want the !nextstream command to display how long until the next planned stream, and if the countdown reaches 0 (when the timer starts going in reverse) the command will tell the user the Streamer should be live.
The trick is that I want to be able to set the date for !nextstream using !setstream, but if I were to use that command as is in the snippet above, the command would parse the IF and edit !nextstream with the output of the condition, instead of embedding the entire code into it.

I used the trick of “$”+"(countdown)" to make sure the countdown doesn’t get parsed until it’s in the right command, but I can’t figure out how to do the same for the entire code >_<

Thanks so much in advance!

EDIT NOTE: For those interested yet wondering about the if (x.match(/ago/g)) bit of the code:
When a specific Date is added to the $(countdown) variable, and that countdown reaches zero, the count will go in reverse and Nightbot’s response will look something like "10 seconds ago". What the code is doing is searching the response for that word, and if found it means the countdown must have reached 0, so it responds with "The streamer should be live!".

you need the !nextstream command to have the eval, so you need the eval to output the eval (hella meta).

@night – I’ve tried :frowning: Tried several ways to pass it all along but couldn’t manage.

!addcom !setstream -a=!editcom !nextstream $(eval "$(eval x="$"+"(countdown $(query) US/Eastern)"; if (x.match(/ago/g)) {"User should be 🔴Live! (If not, stay tuned!)"} else {"🔴 The next stream is planned in "+x})")

^ That doesn’t work :frowning: neither does encasing the eval’s $ and the rest of the code in quotes and adding a + in-between like what I’m doing with $(countdown). The latter example makes it so Nightbot embeds the “Right-hand side of “instanceof” is not an object” error into !nextstream >_<

Could you give me an example of what you meant exactly, if it’s different from the above? Much appreciated if you do!

You need to escape the nested eval… "$" + "(eval

@night – I tried that as well :frowning:

This command:

!addcom !setstream -a=!editcom !nextstream $(eval "$"+"(eval x="$"+"(countdown $(query) US/Eastern)"; if (x.match(/ago/g)) {"User should be 🔴Live! (If not, stay tuned!)"} else {"🔴 The next stream is planned in "+x})")

Results in:
Right-hand side of ‘instanceof’ is not an object

Or is that not what you meant?

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