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?
ANY MINUTE TIMER (up to one hour)
$(eval i=$(querystring);
if(i < 1){
if(i <= 60){
j=i12;
“$(urlfetch https://rokbot.xyz/smm.php?msg="+i+" minute timer started"+(j*4)+" seconds”+(j3)+" 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
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.
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;
“https://rokbot.xyz/smm.php?msg="+i+" minute timer started"+(j*4)+" seconds”+(j3)+" 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”;
}
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 x—x 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.
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.
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.