vylbot-app/src/helpers/CacheHelper.ts
Ethan Lane 5f054b02a5
All checks were successful
continuous-integration/drone/push Build is passing
Add cache helper to update user cache every 30 minutes
2024-03-01 18:25:24 +00:00

27 lines
No EOL
830 B
TypeScript

import { Guild } from "discord.js";
import Server from "../database/entities/Server";
export default class CacheHelper {
public static async UpdateServerCache(guild: Guild) {
const cacheInterval = process.env.CACHE_INTERVAL;
if (!cacheInterval) return;
let server = await Server.FetchOneById(Server, guild.id);
if (!server) {
server = new Server(guild.id);
await server.Save(Server, server);
await CacheHelper.UpdateCache(guild);
} else if (server.LastCached.getTime() + Number(cacheInterval) < Date.now()) {
await CacheHelper.UpdateCache(guild);
}
}
private static async UpdateCache(guild: Guild) {
console.log(`Updating cache for ${guild.name} (${guild.id})`);
await guild.members.fetch();
}
}