Discord account Linkage, penalty update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { MissionLog, NotificationPayload, prisma } from "@repo/db";
|
||||
import { DISCORD_ROLES, MissionLog, NotificationPayload, prisma } from "@repo/db";
|
||||
import { io } from "index";
|
||||
import cron from "node-cron";
|
||||
import { changeMemberRoles } from "routes/member";
|
||||
|
||||
const removeMission = async (id: number, reason: string) => {
|
||||
const log: MissionLog = {
|
||||
@@ -34,7 +35,6 @@ const removeMission = async (id: number, reason: string) => {
|
||||
|
||||
console.log(`Mission ${updatedMission.id} closed due to inactivity.`);
|
||||
};
|
||||
|
||||
const removeClosedMissions = async () => {
|
||||
const oldMissions = await prisma.mission.findMany({
|
||||
where: {
|
||||
@@ -140,6 +140,57 @@ const removeConnectedAircrafts = async () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
const removePermissionsForBannedUsers = async () => {
|
||||
const activePenalties = await prisma.penalty.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
type: "BAN",
|
||||
suspended: false,
|
||||
},
|
||||
{
|
||||
type: "TIME_BAN",
|
||||
suspended: false,
|
||||
until: {
|
||||
gt: new Date().toISOString(),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
include: {
|
||||
User: {
|
||||
include: {
|
||||
DiscordAccount: true,
|
||||
FormerDiscordAccounts: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
activePenalties.forEach(async (penalty) => {
|
||||
const user = penalty.User;
|
||||
|
||||
if (user.DiscordAccount) {
|
||||
await changeMemberRoles(
|
||||
user.DiscordAccount.discordId,
|
||||
[DISCORD_ROLES.PILOT, DISCORD_ROLES.DISPATCHER],
|
||||
"remove",
|
||||
);
|
||||
}
|
||||
|
||||
user.FormerDiscordAccounts.forEach(async (formerAccount) => {
|
||||
await changeMemberRoles(
|
||||
formerAccount.discordId,
|
||||
[DISCORD_ROLES.PILOT, DISCORD_ROLES.DISPATCHER],
|
||||
"remove",
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
cron.schedule("*/5 * * * *", async () => {
|
||||
await removePermissionsForBannedUsers();
|
||||
});
|
||||
|
||||
cron.schedule("*/1 * * * *", async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user