From aabef982e5a7833a0d7d8480212e7c66d97e4ca1 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:15:16 +1100 Subject: [PATCH] It's like trying to repair a hole in a car tire. --- src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index b5ab9f7..c8c3290 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,7 +66,10 @@ setInterval(async()=>{ if (!dailyMsgs.find(x=>x.dataValues.day === formattedDate)) { let total = (await client.userLevels.fetchEveryone()).reduce((a,b)=>a + b.messages, 0); // Sum of all users const yesterday = dailyMsgs.find(x=>x.day === formattedDate - 1) - if (total < yesterday?.total) total = yesterday.total; // Messages went down. + if (yesterday && total < yesterday.total) Logger.console('log', 'DailyMsgs', `Total messages for day ${formattedDate} is less than total messages for day ${formattedDate - 1}.`); + // Update total if it's the same as yesterday's total + if (yesterday && total === yesterday.total) total = (await client.userLevels.fetchEveryone()).reduce((a,b)=>a + b.messages, 0); // Recalculate total + await client.dailyMsgs.newDay(formattedDate, total); Logger.console('log', 'DailyMsgs', `Pushed [${formattedDate}, ${total}]`)