blob: a06705b05c270be08941edb9ce7c54766a19f336 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import client from "./client.js";
pineafane625d782022-05-09 18:04:32 +01002
3class Memory {
4 memory: {};
5 constructor() {
6 this.memory = {};
pineafan6702cef2022-06-13 17:52:37 +01007
8 setInterval(() => {
9 for (let guild in this.memory) {
10 if (this.memory[guild].updated + 15 * 60 * 1000 < Date.now()) {
11 delete this.memory[guild];
12 }
13 }
14 }, 1000 * 60 * 30)
pineafane625d782022-05-09 18:04:32 +010015 }
16
17 async readGuildInfo(guild: string): Promise<object> {
18 if (!this.memory[guild]) {
pineafan4edb7762022-06-26 19:21:04 +010019 let guildData = await client.database.guilds.read(guild);
pineafane625d782022-05-09 18:04:32 +010020 this.memory[guild] = {
pineafan6702cef2022-06-13 17:52:37 +010021 lastUpdated: Date.now(),
pineafane625d782022-05-09 18:04:32 +010022 filters: guildData.filters,
23 logging: guildData.logging,
24 tickets: guildData.tickets,
pineafan6702cef2022-06-13 17:52:37 +010025 };
26 };
pineafane625d782022-05-09 18:04:32 +010027 return this.memory[guild];
28 }
29}
30
pineafan6702cef2022-06-13 17:52:37 +010031export default Memory;