From f7d14cb7f064eb8239ba678aa3fef86aab225816 Mon Sep 17 00:00:00 2001 From: Farhad Jay Date: Wed, 25 Dec 2024 22:53:47 -0800 Subject: [PATCH] Reduce duplicate logic when buidling response --- lib/commands/implementations/schedule.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/commands/implementations/schedule.js b/lib/commands/implementations/schedule.js index 77b5c35..acba291 100644 --- a/lib/commands/implementations/schedule.js +++ b/lib/commands/implementations/schedule.js @@ -12,26 +12,26 @@ function getNextStreamDate(input, services) { const { allDay, name, start, childEvent } = nextStreamDay; const isHappening = start.isBefore(moment()); - const startTime = start.fromNow(); - const link = services.schedule.link(); let scheduleOutput = ''; - if (isHappening) { - scheduleOutput = allDay - ? `${name}, an all-day event, is scheduled today. ${link}` - : `${name} is currently happening! It started ${startTime}. ${link}`; - - if (allDay && childEvent) { + if (isHappening && allDay) { + scheduleOutput = `${name}, an all-day event, is scheduled today.`; + if (childEvent) { const childEventIsHappening = moment(childEvent.start).isBefore(moment()); + // prettier-ignore - scheduleOutput = childEventIsHappening - ? `${name}, an all-day event, is scheduled today. ${childEvent.name} is currently happening! It started ${childEvent.start.fromNow()}. ${link}` - : `${name}, an all-day event, is scheduled today. Coming up ${childEvent.start.fromNow()} is ${childEvent.name}. ${link}`; + scheduleOutput += childEventIsHappening + ? ` ${childEvent.name} is currently happening! It started ${childEvent.start.fromNow()}.` + : ` Coming up ${childEvent.start.fromNow()} is ${childEvent.name}.`; } + } else if (isHappening) { + scheduleOutput = `${name} is currently happening! It started ${start.fromNow()}.`; } else { - scheduleOutput = `${name} is the next scheduled event. It starts ${startTime}. ${link}`; + scheduleOutput = `${name} is the next scheduled event. It starts ${start.fromNow()}.`; } + scheduleOutput += ` ${services.schedule.link()}`; + return new CommandOutput(null, scheduleOutput); }) .catch((err) => new CommandOutput(err, "Oops. Something didn't work. Check the logs."));