Combined Timer Command

I have MULTIPLE timer commands. !timer1 starts a 1 minute timer that uses a 3rd party PHP, and so on. Because the script used is simple, I’m sure I can automate it using a single command. I made an attempt but it isn’t working. Can you assist with understanding what is wrong with it?

$(urlfetch Minute timer started48 seconds36 seconds24 seconds12 seconds`Time’s up&i=12&d=1)

ANY MINUTE TIMER (up to one hour)
$(eval i=$(querystring);
if(i < 1){
if(i <= 60){
“$(urlfetch"+i+" minute timer started"+(j*4)+" seconds”+(j
3)+" seconds"+(j*2)+" seconds"+j+" seconds`Time’s up&i="+j+"&d=1)";
else {
“The requested timer is over an hour and not started.”;
else{ “Invalid Timer Requested”;

You’ll wanna do the eval inside of the urlfetch the urlfetch is called before the eval even starts otherwise you’ll probably have to use an alias to send the final urlfetch to a second command that can detect whether or not a timer started

can you please show me an example? Maybe some other thread that uses something like this?

As far as I know of this is the first like this but I have made a command before that uses a similar idea [CustomAPI] BlackJack command it take the input in the first one structures the output then that out put gets given to a second command that then outputs the message.

Hey @chykityta!

Timers using such API won’t work above 5min of total runtime as it’s the lifetime of the Nightbot token.

1 Like

Good to know. Once I figure out how to get it working, I’ll limit it from 1 to 5 minutes then. Thanks for that!

I don’t understand how this post helps me.

I changed it to 5 minutes as the max and attempted to swap so that urlfetch goes first and eval goes inside but it still doesn’t work for me. Here is the code:

$(urlfetch $(eval i=$(querystring);
if(i < 1){
if(i <= 5){
j=i12;"+i+" minute timer started"+(j*4)+" seconds”+(j
3)+" seconds"+(j*2)+" seconds"+j+" seconds`Time’s up&i="+j+"&d=1)";
else {
“The requested timer is over an hour and not started.”;
else{“Invalid Timer Requested”;

I’m not sure I clearly understand what you’re trying to achieve, but have a look here, I have a feeling that’s what you’re looking for: Nightbot individual chatter timers - #2 by EmilyPerrimon

1 Like

Yes @Emily but I don’t care about the ID of the person and I want to limit the timer from 1 minute to 5 minutes–hence the extra code.

It’s not more or less code, there’s only a few changes to do, it’s not that much:

!addcom !timer -a=_timer $(eval q=`$(1)`; isNaN(q)||q<1?i=60000:q>5?i=300000:i=q*60000;i)
!addcom _timer $(urlfetch$(eval `${$(query)/60000} minutes timer starting...`)/The timer ended.?i=$(query)&d=1)
1 Like

why two commands? what does each do?

The first one converts the amount of minutes to the format the multiple message API understands, it also makes sure that it’s a number of minutes that is fed into the command, and that it’s between 1 and 5 minutes.
The second command is an alias of the first one, which means it’s called right after the first one and that the output of the first command is fed into it, it contains the API that makes the timer possible.
We need two commands because of how Nightbot processes variables, or basically how JS works.
So you just need to call the first command with the amount of minutes you wish your timer to be: !timer xx being the amount of minutes.


Thank you Emily… how can I learn more about the coding language being used here since I feel like most responses are given with the assumption that users know the language inside out?

The language we write commands in is JavaScript as it’s the one Nightbot understands. We also know the documentation.
We don’t write the commands with the assumption people know how it works. Most people never ask and only care if it the commands give the results they want or not, and it would take us too much time to explain the commands in detail every time we write code for people.
We’re all volunteers, we have other things to do, so we can’t afford to waste time on explaining things people don’t care about. But if someone ask we gladly explain, and we try to make it as beginner-friendly as possible.
That’s said, I forgot to tell you that you only need to call the first command when I gave you the commands, that’s my bad.

1 Like

Oh, I do understand and didn’t mean to offend but I’ve written a little bit in C and can’t seem to be able to write code for Nightbot in such way where it’s clean (or readable for me), like other languages, and easy to follow. I don’t want to be given commands and move on–I legitimately want to learn to create them myself–hence my question.

Sorry if it came out as if I was offended, I wasn’t.
I also learned a bit of C before jumping into JS, I believe knowing C helped me greatly—and still does—when it came to understanding it as a new language.
That said, when we write commands for Nightbot, it’s not the cleanest, because we have to save on characters as much as possible, so it’s not the best way to learn JS. I never write code this way outside of Nightbot commands.
If I can recommend a few good resources to learn JS, there’s W3Schools for beginners, and MDN for more advanced stuff. I started with W3Schools, it was great, until I found it didn’t go deep enough, but I couldn’t understand the MDN documentation until I had a good grasp of the language.

1 Like

I added the code but never really tested it until a few days ago and forgot to mention here what the results were. When I call !timer #, I get the following:

chykityta: !timer 1
Nightbot: -a=_timer 60000

Also, nothing happened after a minute–as if the timer didn’t run. Please advise.

Sounds like you added the commands through the dashboard and copy/pasted the -a=_timer part in the response field. So remove it, and put _timer in the alias field.
The code I gave was to add the commands through the chat, if you add it through the dashboard, you need to dispatch the elements as the !addcom command would.

1 Like