cron zum aktuallisieren der Discord Avatare hinzugefügt
This commit is contained in:
@@ -3,6 +3,7 @@ import { io } from "index";
|
||||
import cron from "node-cron";
|
||||
import { setUserStandardNamePermissions } from "routes/helper";
|
||||
import { changeMemberRoles } from "routes/member";
|
||||
import client from "./discord";
|
||||
|
||||
const removeMission = async (id: number, reason: string) => {
|
||||
const log: MissionLog = {
|
||||
@@ -121,6 +122,37 @@ const removeClosedMissions = async () => {
|
||||
return removeMission(mission.id, "dem freimelden aller Stationen");
|
||||
});
|
||||
};
|
||||
|
||||
const syncDiscordImgUrls = async () => {
|
||||
try {
|
||||
const discordAccounts = await prisma.discordAccount.findMany({
|
||||
where: {
|
||||
updatedAt: {
|
||||
lt: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
|
||||
},
|
||||
User: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
});
|
||||
for (const account of discordAccounts) {
|
||||
client.users.fetch(account.discordId).then((discordUser) => {
|
||||
const nextAvatar = discordUser?.avatar ?? null;
|
||||
if (typeof nextAvatar !== "string") return;
|
||||
if (nextAvatar === account.avatar) return;
|
||||
prisma.discordAccount.update({
|
||||
where: {
|
||||
id: account.id,
|
||||
},
|
||||
data: {
|
||||
avatar: nextAvatar,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (error) {}
|
||||
};
|
||||
|
||||
const removeConnectedAircrafts = async () => {
|
||||
const connectedAircrafts = await prisma.connectedAircraft.findMany({
|
||||
where: {
|
||||
@@ -216,7 +248,13 @@ const removePermissionsForBannedUsers = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
removePermissionsForBannedUsers();
|
||||
cron.schedule("0 0 * * *", async () => {
|
||||
try {
|
||||
await syncDiscordImgUrls();
|
||||
} catch (error) {
|
||||
console.error("Error on daily cron job:", error);
|
||||
}
|
||||
});
|
||||
|
||||
cron.schedule("*/1 * * * *", async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user