From d3d66ded459cfc992fb33ab35a3efb9d75e8781c Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Thu, 16 May 2024 09:14:12 -0700 Subject: [PATCH] add profile caching --- src/client.ts | 12 +++++++++++- src/types/index.ts | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 589ccaa..2fd4645 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,4 +1,4 @@ -import { MethodCall, TCJSONResponse, TCResponse, TCResponseRaw } from "./types"; +import { MethodCall, TCJSONResponse, TCProfile, TCResponse, TCResponseRaw } from "./types"; import { AskModule } from "./ask"; import { MessagesModule } from "./messages"; import { ForumModule } from "./forum"; @@ -31,6 +31,8 @@ export class Client { /** @internal */ public _cache: { [key: string]: any; } = { }; + public profileCache: { [key: string]: TCProfile } = { }; + public auth?: string; public agent: string = "pecans"; @@ -121,6 +123,10 @@ export class Client { profiles: res?.profiles, }; + res?.profiles?.forEach((profile) => { + this.profileCache[profile.id] = profile; + }); + resolve(new creator(rawResponse)); }) .catch((reason) => reject(reason)); @@ -165,6 +171,10 @@ export class Client { profiles: res?.profiles, }; + res?.profiles?.forEach((profile) => { + this.profileCache[profile.id] = profile; + }); + c.resolve(new c.creator(individualResponse)); }); }) diff --git a/src/types/index.ts b/src/types/index.ts index 568114a..41b32d9 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -27,6 +27,10 @@ export class TCResponse { this.error = response.error; this.profiles = response.profiles; } + + public toObject(): {[key: string]: any} { + return { ...this }; + } } export interface TCResponseConstructor { @@ -45,5 +49,9 @@ export interface TCProfile { readonly name: string; readonly online: number; readonly avatar: string; + readonly subs: { + readonly in: number; + readonly out: number; + } }