Skip to content

Commit

Permalink
update council list every 10 minutes instead of every 20
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatCats committed Jul 21, 2024
1 parent ce75d1a commit 155f342
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/modules/council/council-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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(" | ")
Expand Down

0 comments on commit 155f342

Please sign in to comment.