From 4d591f80e5b53efb01c836406e65b69d7fea1151 Mon Sep 17 00:00:00 2001 From: WhatCats Date: Mon, 22 Jul 2024 00:09:42 +0200 Subject: [PATCH] update council list every 10 minutes instead of every 20 --- src/modules/council/council-list.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/modules/council/council-list.ts b/src/modules/council/council-list.ts index 40b1b90..dec78e6 100644 --- a/src/modules/council/council-list.ts +++ b/src/modules/council/council-list.ts @@ -25,11 +25,12 @@ for (const rank of Object.values(RANKS)) { export class CouncilListFeature extends BotModule { protected async onReady() { - // Run every :00, :20, :40 - const closest = [20, 40, 60].map((n) => n - new Date().getUTCMinutes()).filter((v) => v > 0) + // Run every :00, :10, :20, :30, :40, :50 + const date = new Date() + const next = Math.ceil(date.getUTCMinutes() / 10) * 10 setTimeout( - () => setInterval(() => this.update().catch(console.error), 20 * 60 * 1000), - Math.min(...closest) * 60 * 1000, + () => setInterval(() => this.update().catch(console.error), 10 * 60 * 1000), + date.setUTCMinutes(next, 0, 0) - Date.now(), ) this.bot.on("initialized", () => this.update().catch(console.error)) @@ -92,10 +93,8 @@ export class CouncilListFeature extends BotModule { await profile?.fetchMCUsername(), member.toString(), currentTime && - currentTime - .set({ minute: Math.floor(currentTime.minute / 10) * 10 }) - .plus({ minutes: 10 }) - .toFormat("h:mm a") + ` (GMT${profile?.getUTCOffset()})`, + currentTime.set({ minute: Math.round(currentTime.minute / 10) * 10 }).toFormat("h:mm a") + + ` (GMT${profile?.getUTCOffset()})`, ] .filter((v) => v) .join(" | ")