pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 1 | import client from "./client.js"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 2 | |
3 | class Memory { | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 4 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
5 | memory: Record<string, any>; | ||||
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | constructor() { |
7 | this.memory = {}; | ||||
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 8 | |
9 | setInterval(() => { | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 10 | for (const guild in this.memory) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 11 | if (this.memory[guild].updated + 15 * 60 * 1000 < Date.now()) { |
12 | delete this.memory[guild]; | ||||
13 | } | ||||
14 | } | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 15 | }, 1000 * 60 * 30); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 16 | } |
17 | |||||
18 | async readGuildInfo(guild: string): Promise<object> { | ||||
19 | if (!this.memory[guild]) { | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 20 | const guildData = await client.database.guilds.read(guild); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 21 | this.memory[guild] = { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 22 | lastUpdated: Date.now(), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 23 | filters: guildData.filters, |
24 | logging: guildData.logging, | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 25 | tickets: guildData.tickets |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 26 | }; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 27 | } |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 28 | return this.memory[guild]; |
29 | } | ||||
30 | } | ||||
31 | |||||
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 32 | export default Memory; |