Uptime command that can add vods lengths

Hello!

I need help with a customized !uptime command.

Sometimes the streamer needs to restart the stream (more than once) due to technical difficulties, which makes the time shown with the Twitch !uptime command to reset. So, I would like to have a “special” !uptime command that would work like this:

!uptime N

The command above would return the length/duration of the current livestream added to the sum of the lengths/durations of the “N” latest previous recorded VODs stored on Twitch.

Also, if used normally, without an argument:

!uptime

Only the length/duration of the current livestream would be returned, just like it normally would work.

That way we could use the !uptime command to show the current length/duration of the livestream… or add the number of VODs that happened that day to make the command return the total time since the streamer started to stream.

So far, what I’ve got to start is a code that gave me the number of hours, minutes and seconds of the current livestream in a array “t”:

$(eval u=`$(twitch $(channel) "{{uptimeLength}}")`;t=u.match(/\d+/g);if(t==null){`channel is not live`}else{while(t.length<3){t.unshift(0);}`${t[0]} hours ${t[1]} minutes ${t[2]} seconds`})

Now I need a code able to fetch the duration of the latest VOD in a way that I can also get the number of hours, minutes and seconds of the VOD and add it to the numbers I have in the array “t”. And make it runs for the “previous” VOD from there, recursively, inside a while until the number of times is equal to N, from my first example.

However, I really don’t know how to do this.

If that could be done within Nightbot, or using an external code stored in a Pastebin file, it would also be great.

Is it possible? And if it is, could anyone please help me?

I managed to get another step closer. With the command below I can get the hours, minutes and seconds of the current livestream (when I use offset = 0 and the streamer is live), the latest Vod (with offset = 1) and if I add to the offset I can get the next latest vods durations as well, individually:

!addcom !uptime2 $(eval u=`$(urlfetch https://decapi.me/twitch/vod_replay/:channel?offset=1)`;t=u.match(/\d+/g);if(t==null){t=0;}else{while(t.length<3){t.unshift(0);};`${parseInt(t[1])} hours ${parseInt(t[2])+5} minutes ${parseInt(t[3])} seconds`})

(the correction of 5 minutes is needed since the vod_replay returns times 5 minutes prior the end of the vod)

Now, if anyone is able to help, please tell me how to make this command get the durations and add, inside a while (from offset 0 to N, where N is a parameter written after the !uptime2 command) to three variables (hours, minutes and seconds), correct them if minutes/seconds > 60 and return the message “X hours XX minutes XX seconds”?

I managed, with some external help, to get another step closer, but I still need help to make the final push.

The following code gets the current uptime from $(twitch $(channel) "{{uptimeLength}}"), which is more accurate, and runs through the number of vods (number of vods is a parameter given by $(1) after the command), getting their duration from the response given by decapi.me (or it would do that…) and sums it to the total time.

!editcom !uptime2 $(eval 
	u=`$(twitch $(channel) "{{uptimeLength}}")`;
	t=u.match(/\d+/g);
	if(t==null) { `channel is not live` }
	else { while(t.length<4) { t.unshift(0) };
		dy=parseInt(t[0]);
		h=parseInt(t[1]);
		m=parseInt(t[2]);
		s=parseInt(t[3]);
		for(i=1; i<=$(1); i++){
			u=`$(urlfetch 'https://decapi.me/twitch/vod_replay/CHANNEL?offset='+i)`;
			t=u.match(/\d+/g);
			t[0]=0;
			while(t.length<5) { t.unshift(0) };
			dy+=parseInt(t[1]);
			h+=parseInt(t[2]);
			m+=parseInt(t[3])+5;
			s+=parseInt(t[4])
		};
		{`$(channel) has been streaming for: ${dy} days ${h} hours ${m} minutes ${s} seconds`}
	}
)

Where dy = days, h = hours, m = minutes and s = seconds.

However, the main issue I’m having is that u=`$(urlfetch 'https://decapi.me/twitch/vod_replay/CHANNEL?offset='+i)`; is always returning the same response as if I’ve set offset=0 (which kinda is the duration of the current livestream, with some delay). It’s not making the variable “i” count as part of the link for each iteration of the “for” loop, in order to get the duration of the vods with offset=1, =2 and so on.

If I was able to make the parameter offset equals the dynamic variable i in the link of this command, it would finally work as intended.

When it works, I will need to find a way to reduce the command to make it fit Nightbot’s character limit.

Can someone help me fix the command and make it fit the 500 character’s limit?

I can tell you that the way nightbot does variables is that it goes from inner most to outer most. And that means that your only urlfetching the link one time. It can’t be called multiple times like that.
Also if character limits is a problem look in something like pastebin

1 Like

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