From 2d6cdd3fc8edd5fc881ef2462ee9835c80f38282 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Fri, 16 Aug 2024 00:55:34 +0000 Subject: [PATCH 1/3] Push back goal date --- api/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app.js b/api/app.js index d8be03e..2b58d07 100644 --- a/api/app.js +++ b/api/app.js @@ -15,7 +15,7 @@ const token = process.env.SLACK_BOT_TOKEN; const channel = process.env.SLACK_MILLION_CHANNEL; const port = process.env.PORT ?? 3000; -const goalDate = '3/1/2024'; +const goalDate = '10/1/2024'; const goalNumber = 300000; const app = new App({ From b2832c7427403d435dc6a8ed1cc820dcb1d3c694 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Fri, 16 Aug 2024 01:00:12 +0000 Subject: [PATCH 2/3] Adjust priority of slices --- api/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app.js b/api/app.js index 2b58d07..1779715 100644 --- a/api/app.js +++ b/api/app.js @@ -24,7 +24,7 @@ const app = new App({ }); function extractNumber(txt) { - let array = ["\n", " ", "-"] + let array = ["-", " ", "\n"] for (let i of array) { if (txt.includes(i)) { return txt.split(i)[0] From c5390c3909d31536823d324af1d92c94bcd7cd17 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Fri, 16 Aug 2024 01:29:20 +0000 Subject: [PATCH 3/3] Properly handle when days roll over to being negative --- api/app.js | 13 +++++++++---- api/quotes.js | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/api/app.js b/api/app.js index 1779715..6fea014 100644 --- a/api/app.js +++ b/api/app.js @@ -173,9 +173,14 @@ async function report() { function predictSpeed(goalDate, goalNumber, currentNumber) { let today = new Date(); let goal = new Date(goalDate); - let timeRemaining = Math.abs(goal - today); - let daysRemaining = Math.ceil(timeRemaining / (1000 * 60 * 60 * 24)); - let neededSpeed = (goalNumber - currentNumber) / daysRemaining; + let timeRemaining = goal - today; + let daysRemaining + if (timeRemaining >= 0) { + daysRemaining = Math.ceil(timeRemaining / (1000 * 60 * 60 * 24)); + else { + daysRemaining = math.floor(timeRemaining / (1000 * 60 * 60 * 24)); + } + let neededSpeed = (goalNumber - currentNumber) / Math.abs(daysRemaining); return [daysRemaining, neededSpeed]; } @@ -238,4 +243,4 @@ app.event('app_mention', async (body) => { } catch (error) { console.error(error); } -})(); +})(); \ No newline at end of file diff --git a/api/quotes.js b/api/quotes.js index 80f848c..ff0120d 100644 --- a/api/quotes.js +++ b/api/quotes.js @@ -22,19 +22,23 @@ let regularEndQuotes = [ function addQuotes(message, rawGoals, rawSpeed) { let start = regularStartQuotes[Math.floor(Math.random() * regularStartQuotes.length)] - let end =regularEndQuotes[Math.floor(Math.random() * regularEndQuotes.length)]; + let end = regularEndQuotes[Math.floor(Math.random() * regularEndQuotes.length)]; let goals = Math.ceil(rawGoals[1]); let days = rawGoals[0]; let speed = Math.round(rawSpeed); let diff = goals - speed; if (goals <= 0) { end = `:tada: YOU DID IT, MY LOYAL SERVANTS! YOU'VE REACHED OUR GOAL ON TIME! :tada: But there's still loads of time before we reach a million-- let's keep up the pace!` - } else if (diff < 10) { + } else if (diff < 10 && days > 0) { end = `You're doing well, my lackeys! Keep up that speed of at least *+${speed}* if you want to reach that goal! You have *${days}* days remaining to get there!` - } else if (diff > 10 && diff < 1000) { + } else if (diff > 10 && diff < 1000 && days > 0) { end = `Still room to improve your performance, my underlings-- you're only at *${speed}* a day! Get that speed up to at least *+${goals}* to get there on time! You have *${days}* days left!` - } else if (diff > 1000) { + } else if (diff > 1000 && days > 0) { end = `You're slogging behind, my minions! Only *${speed}* a day? RiDONKulous! Get that speed up to at least *+${goals}* to get there on time! Hurry up!!! You have *${days}* days left to get there!` + } else if (days == 0) { + end = `Today's the deadline my minions! I hope you can count at least *+${goals}* today, otherwise we'll miss the deadline!` + } else if (days < 0) { + end = `We've missed the deadline by ${Math.abs(days)} day${(days < -1)? 's': ''} my underlings-- I hope you can make the next one. In the meantime, I recommend counting *+${goals}* numbers today.` } return start + "\n" + message + "\n" + end; }