sendou.ink/app/routines/notifyCheckInStart.ts
Kalle 869ab6a10f
Test tournaments, prematch chat & counterpicking with mode repeat (#2242)
* Initial

* Test tournaments

* Pre-match chat
2025-05-01 12:26:13 +03:00

47 lines
1.4 KiB
TypeScript

import * as CalendarRepository from "../features/calendar/CalendarRepository.server";
import { notify } from "../features/notifications/core/notify.server";
import { tournamentDataCached } from "../features/tournament-bracket/core/Tournament.server";
import { logger } from "../utils/logger";
import { Routine } from "./routine.server";
export const NotifyCheckInStartRoutine = new Routine({
name: "NotifyCheckInStart",
func: async () => {
const now = new Date();
const oneHourFromNow = new Date(now.getTime() + 60 * 60 * 1000);
const tournaments = await CalendarRepository.findAllBetweenTwoTimestamps({
startTime: now,
endTime: oneHourFromNow,
onlyTournaments: true,
});
for (const { tournamentId } of tournaments) {
const tournament = await tournamentDataCached({
tournamentId: tournamentId!,
user: undefined,
});
if (tournament.ctx.settings.isTest) {
continue;
}
logger.info(
`Notifying check-in start for tournament ${tournament.ctx.id}`,
);
await notify({
notification: {
type: "TO_CHECK_IN_OPENED",
meta: {
tournamentId: tournament.ctx.id,
tournamentName: tournament.ctx.name,
},
pictureUrl: tournament.ctx.logoSrc,
},
userIds: tournament.ctx.teams
.flatMap((team) => team.members.map((member) => member.userId))
.concat(tournament.ctx.staff.map((staff) => staff.id)),
});
}
},
});