Skip to content

Commit

Permalink
refactor executeDailyWebhook logic
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Oct 16, 2023
1 parent 0ac9cbe commit 9896822
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions api/dailies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,27 @@ async function executeDailyWebhook(
): Promise<Response> {
// Get the daily question.
const question = await lcClient.getDailyQuestion();
const questionDate = new Date(`${question.date} GMT`);
const isSunday = questionDate.getDay() === 0;

// Get the stored season.
const storedSeason = seasonID
? await leaderboardClient.getSeason(seasonID)
: await leaderboardClient.getLatestSeason();

// If the season is ongoing, then sync it.
const referenceDate = new Date(`${question.date} GMT`);
const syncedSeason = (
storedSeason &&
leaderboard.checkDateInWeek(
new Date(storedSeason.start_date).getTime(),
referenceDate.getTime(),
)
)
const referenceDate = new Date();
const isLatestSeason = storedSeason && leaderboard.checkDateInWeek(
new Date(storedSeason.start_date).getTime(),
referenceDate.getTime(),
);
const syncedSeason = isLatestSeason
? await leaderboardClient
.sync(storedSeason.id)
.then((response) => response.season)
: null;

// Format the webhook embed.
const isSunday = new Date(question.date).getDay() === 0;
const embeds = makeDailyWebhookEmbeds({
question,
season: isSunday ? (syncedSeason ?? storedSeason) : null,
Expand Down

0 comments on commit 9896822

Please sign in to comment.