Skip to content

Commit

Permalink
Reduce duplicate logic when buidling response
Browse files Browse the repository at this point in the history
  • Loading branch information
11k committed Dec 26, 2024
1 parent 64178f7 commit f7d14cb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/commands/implementations/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
Expand Down

0 comments on commit f7d14cb

Please sign in to comment.