Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Rocket League Ranked Tournament Countdown Timer
- by t00much#8965 and Country Mac#3820 on Discord
- This script is intended for use as a Nightbot Twitch chat command to display a countdown of the
- next scheduled Rocket League RankedTournament. This script only works for US tournaments with
- the time zone defaulted to Pacific. If you need to change the time zone, change the `timeZone`
- variable in the Nightbot command to either 'East', 'Central', or 'Mountain'.
- Nightbot command: !addcom !tt /me $(eval var timeZone='West', user=`$(1)`;$(urlfetch json
- https://pastebin.com/raw/fgEYW0m8))
- */
- var username = (user === 'null') ? '' : user;
- var t = timeZone.toLowerCase();
- Date.prototype.stdTimezoneOffset = function() {
- var jan = new Date(this.getFullYear(), 0, 1);
- var jul = new Date(this.getFullYear(), 6, 1);
- return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
- };
- Date.prototype.isDstObserved = function() {
- return this.getTimezoneOffset() < this.stdTimezoneOffset();
- };
- var today = new Date();
- var DT_or_ST = (today.isDstObserved()) ? 'DT' : 'ST';
- if (t === 'us-east') {
- var TZ = 12,
- TZ_diff = 0,
- TZ_Str = 'E' + DT_or_ST;
- } else if (t === 'us-central') {
- var TZ = 13,
- TZ_diff = 1,
- TZ_Str = 'C' + DT_or_ST;
- } else if (t === 'us-mountain') {
- var TZ = 14,
- TZ_diff = 2,
- TZ_Str = 'M' + DT_or_ST;
- } else if (t === 'us-west') {
- var TZ = 15,
- TZ_diff = 3,
- TZ_Str = 'P' + DT_or_ST;
- } else if (t === 'eu-west') {
- var TZ = 6,
- TZ_diff = -6,
- TZ_Str = 'C' + DT_or_ST;
- } else {
- throw new Error("Invalid US time zone. Nightbot command timeZone variable must be either:
- 'east', 'central', 'mountain', or 'pacific' NotLikeThis")
- }
- const timeTil = h => {
- let d = new Date();
- d.setHours(h, 0, 0, 0);
- return (d - Date.now());
- };
- const formatTimeTil = q => {
- let h, m, s;
- h = Math.floor(q / 1000 / 60 / 60);
- m = Math.floor((q / 1000 / 60 / 60 - h) * 60);
- s = Math.floor(((q / 1000 / 60 / 60 - h) * 60 - m) * 60);
- if (m == 0 && h == 0) return `${s} second${s>1 ? 's' : ''}`;
- else if (h == 0) return `${m} minute${m>1 ? 's' : ''}, ${s} second${s>1 ? 's' : ''}`;
- else if (m == 0) return `${h} hour${h>1 ? 's' : ''}, ${s} second${s>1 ? 's' : ''}`;
- else if (s == 0) return `${h} hour${h>1 ? 's' : ''}, ${m} minute${m>1 ? 's' : ''}`;
- else return `${h} hour${h>1 ? 's' : ''}, ${m} minute${m>1 ? 's' : ''}, ${s}
- second${s>1 ? 's' : ''}`;
- };
- const getTimes = _ => {
- let times = [18, 21],
- now = new Date();
- if ([0, 5, 6].includes(now.getDay)) times.push([12, 15]);
- return times;
- };
- const getClosestTime = _ => {
- let closestTime = getTimes().map(t => ({
- hour: t,
- diff: timeTil(t)
- })).reduce((acc, cur) => {
- return (cur.diff < acc.diff && cur.diff > 0) ? cur : acc;
- }, {
- hour: 24,
- diff: timeTil(24)
- });
- let today = new Date();
- let AoP = (closestTime.hour > 11 && closestTime.hour != 0) ? 'pm' : 'am';
- return `The next tournament starts in ${formatTimeTil(closestTime.diff)} (${(closestTime.hour
- > 12) ? closestTime.hour - TZ : closestTime.hour - TZ_diff} ${AoP} ${TZ_Str}) ${username}`;
- };
- getClosestTime();
Add Comment
Please, Sign In to add comment