Adding a countdown timer that isn't so clunky?

So trying to add a countdown timer which so far from what it seems like the only way is to do a set date/time and it’s static…

I wanna be able to set a time of 1 hour and then after that it counts down till times up so sorta like the following.

!time = displays current time left.
!settime = input like 1 hour or how ever long needed
!resettime = resets back to what ever was set for !settime.

I don’t wanna have to keep deleting and remaking commands all the time if possible??

I’ve made something similar in these two posts, they can probably be reformatted to fit what your looking for.

I feel like I’m missing something I can’t get it to work keeps telling me the timezone stuff is wrong and then links me to the timezones…

something else is I don’t feel like this will work idk… I’ve been looking at it and it seems like it’s based on a specific timezone/date and then it counts down from there?

I wanna be able to do like

!settimer 1 Hour or 1:00:10

then when I do !timer it displays how much time is left and then when I do !resettimer it starts over unless I set a new timer for a different time frame…

Because these commands contain private tokens, you should add them through the Nightbot web interface: https://beta.nightbot.tv/commands/custom.

Go to https://twitch.center/customapi/quote/generate. You will see three lines. Your first token is after token= and before &data= on the first line. Your second token is after token= and before &data= on the second and third lines. Replace FIRSTTOKEN and SECONDTOKEN with these before you add the following commands.

!time
$(eval q=`$(urlfetch http://twitch.center/customapi/quote?token=FIRSTTOKEN&data=1&no_id=1)`,m=q.match(/^(.+)\|\d+$/),m?(t=parseInt((new Date(m[1])-new Date)/1e3),t<=0?"The timer has elapsed":(d=Math.floor(t/86400),h=Math.floor(t/3600)%24,m=Math.floor(t/60)%60,s=t%60,(d>0?d+" day"+(d==1?"":"s"):"")+(h>0?` ${h} hour${h==1?"":"s"}`:"")+(m>0?` ${m} minute${m==1?"":"s"}`:"")+(s>0?` ${s} second${s==1?"":"s"}`:""))):q=="There are no quotes added"?"No time has been set":"!settime is misconfigured")

!settime (userlevel moderator, alias to !settimesetter)
$(eval d=`$(query)`.match(/^(?:(\d+)\s*(?:days?|d))?\s*(?:(\d+)\s*(?:hours?|h))?\s*(?:(\d+)\s*(?:minutes?|m))?\s*(?:(\d+)\s*(?:seconds?|s))?$/i),d&&(d[1]||d[2]||d[3]||d[4])?(s=(d[1]||0)*86400+(d[2]||0)*3600+(d[3]||0)*60+(d[4]||0)*1,e=new Date,e.setSeconds(e.getSeconds()+s),p=e.toJSON()+"|"+s,(`$(urlfetch http://twitch.center/customapi/quote?token=FIRSTTOKEN)`=="There are no quotes added"?"add":(p="1 "+p,"edit"))+"quote?token=SECONDTOKEN&data="+encodeURIComponent(p)):"$NDTN$")

!settimesetter (userlevel moderator)
$(eval r=`$(urlfetch http://twitch.center/customapi/$(query))`;if(r.startsWith("Successfully ")){"The timer was set"}else if(`$(query)`=="$NDTN$"){"Enter a duration after !settime"}else{"Use !settime"})

!resettime (userlevel moderator, alias to !resettimesetter)
$(eval quote=`$(urlfetch http://twitch.center/customapi/quote?token=FIRSTTOKEN&data=1&no_id=1)`;match=quote.match(/^.+\|(\d+)$/);if(match){s=parseInt(match[1]);e=new Date();e.setSeconds(e.getSeconds()+s);"editquote?token=SECONDTOKEN&data="+encodeURIComponent("1 "+e.toJSON()+"|"+s)}else if(quote="There are no quotes added"){"$NOTSET$"}else{"$MISCONFIGURED$"})

!resettimesetter (userlevel moderator)
$(eval r=`$(urlfetch http://twitch.center/customapi/$(query))`;if(r.startsWith("Successfully ")){"The timer was reset"}else if(`$(query)`=="$NOTSET$"){"No time has been set"}else if(`$(query)`=="$MISCONFIGURED$"){"!settime is misconfigured"}else{"Use !resettime"})

Command explanations:

!time:
View the remaining time. If the timer has elapsed, the command returns “No time has been set”.
This command takes up 493 characters, so you have 7 characters to add extra text to the command. You can get more space by reducing the length of the error messages “No time has been set” and “!settime is misconfigured”.

!settime:
Enter a duration such as “3 days 1 hour 4 minutes 40 seconds” or “1h30m” to set the timer.

!settimesetter:
Utility command for !settime. Should not be used manually.

!resettime:
Reset the timer to the duration previously set by !settime, if one exists.

!resettimesetter:
Utility command for !resettime. Should not be used manually.

If the commands don’t work at all, you didn’t properly insert your tokens.

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