Making Nightbot do Math w/ Time?

Asked Mar 12, 2021·8 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I was wondering if theres any way to make Nightbot do addition within the format of 60 sec = 1 minute?

For example typing !example 1530 or 15:30 could make it so that !example triggers nightbot to add 160 seconds to 15:30 to get to 1810 or 18:10. Thanks in advance for your time!

8 replies

Yeah it’s possible any specific parameters?
Like should it always add 180 seconds or should that be changeable?

Here you go

!name_of_command

$(eval dy=0;h=$(1);m=$(2);s=$(3);d=$(4);sn=(d+s)%60;ma=Math.floor((d+s)/60);mn=(m+ma)%60;ha=Math.floor((m+ma)/60);hn=(h+ha)%24;dyn=Math.floor((h+ha)/24);`${dyn==0?``:`${dyn} days`} ${hn==0?``:`${hn} hours`} ${mn==0?``:`${mn} minutes`} ${sn==0?``:`${sn} seconds`}`)

Format is !name_of_command {Hours} {Minutes} {Seconds} {Delay_in_Seconds}
Alternatively you can input your own delay in seconds at d=____ instead of allowing them to input there own. Hope this is up to your standards ;)

Thank you for your help on this! The way I was hoping to implement this would be:

!example 1520 or 15:20 & nightbot would reply with 18:00 or 1800 (+160)
!example2 1520 or 15:20 & nightbot would reply with 17:30 or 1730 (+130)

would that mean replacing the (4) ``d=$(4)`` with the desired amount 130, 160 etc.?

Yes replace $(4) with desired amount of time in seconds

!commands add !beads $(eval dy=0;h=$(1);m=$(2);s=$(3);d=160;sn=d+s%60;ma=Math.floor((d+s)/60);mn=m+ma%60;ha=Math.floor((m+ma)/60);hn=h+ha%24;dyn=Math.floor((h+ha)/24);`${dyn==0?``:`${dyn} days`} ${hn==0?``:`${hn} hours`} ${mn==0?``:`${mn} minutes`} ${sn==0?``:`${sn} seconds`}`)
!beads 0 15 20

gets the result of: 18 Minutes 180 Seconds.

Sorry I forgot to include 3 pairs of parentheses I edited the command above it should work now

Working like a charm. Appreciate your time on this!

Didn't find your answer? The community is on Discord.

Ask on Discord