feat: add fix dialog

This commit is contained in:
2024-12-30 11:19:53 +09:00
parent abacea4f71
commit 6cbeecea87
9 changed files with 275 additions and 92 deletions

View File

@ -15,7 +15,7 @@ import shajs from 'sha.js'
export class Memorizer {
private static memorized = new Map<string, Memorizer>()
public static memo (client: Client<any, any, any, any>, salt = '') {
public static memo(client: Client<any, any, any, any>, salt = '') {
const serialized = JSON.stringify([client.constructor.name, salt])
const hashed = shajs('sha256').update(serialized).digest('hex')
@ -30,6 +30,11 @@ export class Memorizer {
return newMemo
}
public static reset() {
for (const memorized of Memorizer.memorized.values())
memorized.reset()
}
private memorized = new Map<string, any>()
private constructor (
@ -44,9 +49,14 @@ export class Memorizer {
if (memorized !== undefined)
return memorized
console.log(command.constructor.name, 'Executed.')
const newMemo = await this.client.send(command)
this.memorized.set(hashed, newMemo)
return newMemo
}
private readonly reset = () =>
this.memorized.clear()
}