27 lines
No EOL
830 B
TypeScript
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();
|
|
}
|
|
} |