fix: fix wrong client selection

This commit is contained in:
2024-12-26 11:53:29 +09:00
parent ab74b2fcfa
commit eb30242fe1
7 changed files with 14 additions and 11 deletions

View File

@ -15,14 +15,17 @@ import shajs from 'sha.js'
export class Memorizer {
private static memorized = new Map<string, Memorizer>()
public static memo (client: Client<any, any, any, any>) {
const memorized = this.memorized.get(client.constructor.name)
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')
const memorized = this.memorized.get(hashed)
if (memorized !== undefined)
return memorized
const newMemo = new Memorizer(client)
this.memorized.set(client.constructor.name, newMemo)
this.memorized.set(hashed, newMemo)
return newMemo
}