feat: clean up data on bot and member leaves

This commit is contained in:
2024-07-07 13:03:34 -07:00
parent 76cc030534
commit bcdcf4629a
4 changed files with 42 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import { ExtendedClient } from "../interfaces/ExtendedClient";
import { checkEntitledGuild } from "../utils/checkEntitledGuild";
import { errorHandler } from "../utils/errorHandler";
/**
@ -12,6 +13,16 @@ export const maintainSecurity = async (bot: ExtendedClient) => {
const records = await bot.db.security.findMany();
const date = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
for (const record of records) {
const guild =
bot.guilds.cache.get(record.serverId) ||
(await bot.guilds.fetch(record.serverId).catch(() => null));
if (!guild) {
continue;
}
const isEntitled = await checkEntitledGuild(bot, guild);
if (!isEntitled) {
continue;
}
await fetch(
`https://discord.com/api/v10/guilds/${record.serverId}/incident-actions`,
{

View File

@ -1,4 +1,5 @@
import { ExtendedClient } from "../interfaces/ExtendedClient";
import { checkEntitledGuild } from "../utils/checkEntitledGuild";
import { errorHandler } from "../utils/errorHandler";
/**
@ -13,11 +14,19 @@ export const postBirthdays = async (bot: ExtendedClient) => {
const configs = await bot.db.configs.findMany();
const withChannel = configs.filter((c) => c.birthdayChannel);
for (const record of withChannel) {
const guild = bot.guilds.cache.get(record.serverId);
const guild =
bot.guilds.cache.get(record.serverId) ||
(await bot.guilds.fetch(record.serverId).catch(() => null));
if (!guild) {
continue;
}
const channel = guild.channels.cache.get(record.birthdayChannel);
const isEntitled = await checkEntitledGuild(bot, guild);
if (!isEntitled) {
continue;
}
const channel =
guild.channels.cache.get(record.birthdayChannel) ||
(await bot.guilds.fetch(record.birthdayChannel).catch(() => null));
if (!channel || !("send" in channel)) {
continue;
}