blob: 070bd7fa5ec5c9ce93d8abf11aa7d7ab5ff15424 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import client from "./client.js";
pineafane625d782022-05-09 18:04:32 +01002
3class Memory {
pineafan63fc5e22022-08-04 22:04:10 +01004 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5 memory: Record<string, any>;
pineafane625d782022-05-09 18:04:32 +01006 constructor() {
7 this.memory = {};
pineafan6702cef2022-06-13 17:52:37 +01008
9 setInterval(() => {
pineafan63fc5e22022-08-04 22:04:10 +010010 for (const guild in this.memory) {
pineafan6702cef2022-06-13 17:52:37 +010011 if (this.memory[guild].updated + 15 * 60 * 1000 < Date.now()) {
12 delete this.memory[guild];
13 }
14 }
pineafan63fc5e22022-08-04 22:04:10 +010015 }, 1000 * 60 * 30);
pineafane625d782022-05-09 18:04:32 +010016 }
17
18 async readGuildInfo(guild: string): Promise<object> {
19 if (!this.memory[guild]) {
pineafan63fc5e22022-08-04 22:04:10 +010020 const guildData = await client.database.guilds.read(guild);
pineafane625d782022-05-09 18:04:32 +010021 this.memory[guild] = {
pineafan6702cef2022-06-13 17:52:37 +010022 lastUpdated: Date.now(),
pineafane625d782022-05-09 18:04:32 +010023 filters: guildData.filters,
24 logging: guildData.logging,
pineafan63fc5e22022-08-04 22:04:10 +010025 tickets: guildData.tickets
pineafan6702cef2022-06-13 17:52:37 +010026 };
pineafan63fc5e22022-08-04 22:04:10 +010027 }
pineafane625d782022-05-09 18:04:32 +010028 return this.memory[guild];
29 }
30}
31
pineafan6702cef2022-06-13 17:52:37 +010032export default Memory;