chore: suppress deletion errors

This commit is contained in:
2024-07-07 13:55:59 -07:00
parent 58a51f43de
commit 5c68f84d29
5 changed files with 994 additions and 17 deletions

View File

@ -15,13 +15,27 @@ export const onGuildDelete = async function (
await bot.env.debugHook.send({
content: `LEFT GUILD: ${guild.name} (${guild.id}) `
});
await bot.db.cases.deleteMany({ where: { serverId: guild.id } });
await bot.db.levelRoles.deleteMany({ where: { serverId: guild.id } });
await bot.db.levels.deleteMany({ where: { serverId: guild.id } });
await bot.db.configs.deleteMany({ where: { serverId: guild.id } });
await bot.db.roles.deleteMany({ where: { serverId: guild.id } });
await bot.db.birthdays.deleteMany({ where: { serverId: guild.id } });
await bot.db.security.deleteMany({ where: { serverId: guild.id } });
await bot.db.cases
.deleteMany({ where: { serverId: guild.id } })
.catch(() => null);
await bot.db.levelRoles
.deleteMany({ where: { serverId: guild.id } })
.catch(() => null);
await bot.db.levels
.deleteMany({ where: { serverId: guild.id } })
.catch(() => null);
await bot.db.configs
.deleteMany({ where: { serverId: guild.id } })
.catch(() => null);
await bot.db.roles
.deleteMany({ where: { serverId: guild.id } })
.catch(() => null);
await bot.db.birthdays
.deleteMany({ where: { serverId: guild.id } })
.catch(() => null);
await bot.db.security
.deleteMany({ where: { serverId: guild.id } })
.catch(() => null);
} catch (err) {
await errorHandler(bot, "on guild delete", err);
}

View File

@ -20,16 +20,20 @@ export const onMemberRemove = async (
const config = await getConfig(bot, guild.id);
await bot.db.birthdays.delete({
where: {
serverId_userId: { serverId: guild.id, userId: user.id }
}
});
await bot.db.levels.delete({
where: {
serverId_userId: { serverId: guild.id, userId: user.id }
}
});
await bot.db.birthdays
.delete({
where: {
serverId_userId: { serverId: guild.id, userId: user.id }
}
})
.catch(() => null);
await bot.db.levels
.delete({
where: {
serverId_userId: { serverId: guild.id, userId: user.id }
}
})
.catch(() => null);
if (!config.eventLogChannel) {
return;

32
src/temp.ts Normal file
View File

@ -0,0 +1,32 @@
import { PrismaClient } from "@prisma/client";
import data from "../export.json";
import { Client, GatewayIntentBits } from "discord.js";
const id = "443134315778539530";
(async () => {
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers]
});
await client.login(
"MTIzNTEyODcxOTgzNjcxMjk3MA.G46Wds.oXp5dpRKqwfwPhMiLzTgmIVEZI-G_wH2y7lFrk"
);
const guild = client.guilds.cache.get(id);
if (!guild) {
throw new Error("Cannot find Caylus' server.");
}
const members = await guild.members.fetch();
const existing = data
.filter((d) => members.has(d.userId))
.map((d) => ({
userId: d.userId,
serverId: id,
birthday: new Date(d.birthday)
}));
const db = new PrismaClient({
datasourceUrl:
"mongodb+srv://modbot:6NriYlDECa3e9nCC@nhcarrigan.4jqem.mongodb.net/modbot?retryWrites=true&w=majority"
});
await db.birthdays.createMany({ data: existing });
await db.$disconnect();
})();