Is it possible to set permanent variables to call up later?

I am trying to create a “days since last disaster” counter that resets itself when receiving a specific argument.

This is what I came up with:

$(eval var a = “$(query)”; t = “$(time US/Eastern “MMM DD YYYY, hh:mm a”)”;if (a === “reset”) {var b = t; “counter reset”;} else {$(countup ${b});})

My logic is: command gets the current time every time it is ran, if it gets the “reset” argument, it sets variable b to the current time (variable t) to set it for the next time the command is run, if it doesn’t get any arguments, it counts up to variable b (which would have been set upon the first “reset”).

it doesn’t appear to be actually setting the variable b to t. If I run the command first with a reset, to initialize the variable, and then run it again without any argument, variable b is back to being undefined.

Is what I’m trying to do even possible without a custom API?

Thanks!

@octojay

All variables within an $(eval) will be newly declared each time the command is used, so setting variables that Nightbot will keep track of between command uses is impossible (outside of $(eval) there is $(count) but that’s useless for what you need). You would have to make use of an API, specifically ehsankia’s quote list API.


Click this link. It will generate three links and two tokens, a public token (8 characters long) and a private token (16 characters long). The public token is located within the first generated link. The private token is located within both the second and third generated links. The tokens are found after token= and before &data=$(querystring) Copy them and keep them somewhere safe!

I’ve set up 2 commands below, !disaster and !disasterp2 which work in tandem to output a response depending on whether the input is reset. Although this setup creates 2 commands, you are only supposed to use !disaster, and I’ve set it up such that directly using !disasterp2 won’t work. Either copy and paste these commands into chat or add them through the Nightbot dashboard. Add the commands through chat only if you are sure no one else is there, otherwise they might see your private token. Replace PUBLIC_TOKEN with your public token and PRIVATE_TOKEN with your private token.

!addcom -cd=5 !disaster -a=!disasterp2 $(eval decodeURIComponent(`$(querystring)`).toLowerCase()==`reset`?`PRIVATE_TOKEN&data=$(time EST "MMM D Y HH:mm:ss z")`:`PRIVATE_TOKEN COUNTUP`)
!addcom -cd=5 !disasterp2 $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`;if(`$(query)`.includes(`PRIVATE_TOKEN`)){`$(2)`==`COUNTUP`?`It has been $(countup $(urlfetch http://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=0&no_id=1)) since the last disaster.`:`$(user) has reset the disaster counter.`;}else{`Use !disaster`;})

When using !disaster for the first time, enter the “reset” argument so Nightbot will have a time to start counting up from. From there you can use !disaster without the “reset” argument.

1 Like

Thank you very much for the response and the detailed explanation!

Edit: I formatted it all to my liking and it all works beautifully. Thank you again!

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