mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-25 15:56:19 -05:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { currentSeason } from "../features/mmr/season";
|
|
import * as NotificationRepository from "../features/notifications/NotificationRepository.server";
|
|
import { notify } from "../features/notifications/core/notify.server";
|
|
import { isVotingActive } from "../features/plus-voting/core";
|
|
import * as UserRepository from "../features/user-page/UserRepository.server";
|
|
import { Routine } from "./routine.server";
|
|
|
|
export const NotifyPlusServerVotingRoutine = new Routine({
|
|
name: "NotifyPlusServerVoting",
|
|
func: async () => {
|
|
if (!isVotingActive()) return;
|
|
|
|
const season = currentSeason(new Date())!;
|
|
|
|
const plusVotingNotifications = await NotificationRepository.findAllByType(
|
|
"PLUS_VOTING_STARTED",
|
|
);
|
|
|
|
if (
|
|
plusVotingNotifications.some(
|
|
(notification) => notification.meta.seasonNth === season.nth,
|
|
)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
await notify({
|
|
notification: {
|
|
type: "PLUS_VOTING_STARTED",
|
|
meta: {
|
|
seasonNth: season.nth,
|
|
},
|
|
},
|
|
userIds: (await UserRepository.findAllPlusServerMembers()).map(
|
|
(member) => member.userId,
|
|
),
|
|
});
|
|
},
|
|
});
|