sendou.ink/app/routines/notifySeasonStart.ts
Kalle dd1adad94b
Some checks are pending
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run
BIome v2 upgrade
2025-06-22 16:49:27 +03:00

42 lines
1.1 KiB
TypeScript

import { add } from "date-fns";
import * as Seasons from "../features/mmr/core/Seasons";
import { userSkills } from "../features/mmr/tiered.server";
import { notify } from "../features/notifications/core/notify.server";
import * as NotificationRepository from "../features/notifications/NotificationRepository.server";
import { Routine } from "./routine.server";
export const NotifySeasonStartRoutine = new Routine({
name: "NotifySeasonStart",
func: async () => {
const season = Seasons.current();
// old notifications get deleted after 14 days, make sure we don't send the same notification twice
if (!season || add(season.starts, { days: 7 }) < new Date()) {
return;
}
const seasonNotifications =
await NotificationRepository.findAllByType("SEASON_STARTED");
if (
seasonNotifications.some(
(notification) => notification.meta.seasonNth === season.nth,
)
) {
return;
}
const lastSeasonsUsers = userSkills(season.nth - 1).userSkills;
await notify({
notification: {
type: "SEASON_STARTED",
meta: {
seasonNth: season.nth,
},
},
userIds: Object.keys(lastSeasonsUsers).map(Number),
});
},
});