Once per stream message at specific uptime

Hey @AesDraconis!

Yes, of course you can use timers for that, but you have to get creative!

Simply set it up short enough, I recommend the minimum: 5 minutes, and then when the timer runs have it look at the amount of time you’ve been streaming, and only send a message if it’s the right moment of the stream.

You’ll need to use Pastebin, that way you’ll only set up one timer, and you’ll be able to fit all your messages in it.

Code to put in the timer:

$(eval uptime='$(twitch $(channel) "{{uptimeLength}}")'; $(urlfetch json https://pastebin.com/raw/XXXXXXXX))

Code to write in your paste:

const messages = {
	'0000': 'Message at 0 minute of stream time',
	'0035': 'Message at 35 minutes of stream time',
	'0125': 'Message at 1 hour and 25 minutes of stream time',
	'0200': 'Message at 2 hours of stream time',
	'1315': 'Message at 13 hours and 15 minutes of stream time'
};

const messagesTimestamps = Object.keys(messages);

const findData = (string, regex) => string.match(regex) || '0';
const keepAmount = string => string.split(' ').filter(e => isNaN(e) === false);
const normalizeAmount = string => string.padStart(2, '0');
const arrayToString = array => Array.isArray(array) ? array.join('') : array;

const hourRegex = /\d+\s\bhour/;
const minuteRegex = /\d+\s\bminute/;

const hourData = arrayToString(findData(uptime, hourRegex));
const minuteData = arrayToString(findData(uptime, minuteRegex));

const hourAmount = arrayToString(keepAmount(hourData));
const minuteAmount = arrayToString(keepAmount(minuteData));

const normalizedHourAmount = normalizeAmount(hourAmount);
const normalizedMinuteAmount = normalizeAmount(minuteAmount);

const currentTime = normalizedHourAmount.concat(normalizedMinuteAmount);

let timestamp = [];
messagesTimestamps.forEach(e => {
	if (Math.abs(parseInt(e) - parseInt(currentTime)) <= 5) {
		timestamp.push(e);
	}
});

messages[timestamp[0]] || ' ';


• Replace XXXXXXXX in the timer code with the paste ID.
• Feel free to edit the messages in the Pastebin by following exactly the formatting here (of course you can have more than 5 messages); you can change the message times by editing the numbers.
• Make sure the paste is public or unlisted (do not make it private) and that it’s set to never expire.

Please note that it’ll skip messages if your chat isn’t active, messages can also be a bit delayed (by a maximum of 5 minutes).


I recommend setting up a Pastebin account so you can come back later to edit your messages.

2 Likes