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 { |
| 4 | memory: {}; |
| 5 | constructor() { |
| 6 | this.memory = {}; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 7 | |
| 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) |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | async readGuildInfo(guild: string): Promise<object> { |
| 18 | if (!this.memory[guild]) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 19 | let guildData = await client.database.read(guild); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 20 | this.memory[guild] = { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 21 | lastUpdated: Date.now(), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 22 | filters: guildData.filters, |
| 23 | logging: guildData.logging, |
| 24 | tickets: guildData.tickets, |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 25 | }; |
| 26 | }; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 27 | return this.memory[guild]; |
| 28 | } |
| 29 | } |
| 30 | |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 31 | export default Memory; |