Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
fix: add option to fetch if not cached
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Sep 24, 2023
1 parent 9d60994 commit a2b39e2
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions libs/core/src/Structures/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Client extends EventEmitter {
});
}

public async resolveMember({ force = false, cache, id, guildId }: { force?: boolean | undefined; cache?: boolean | undefined; id: string; guildId: string }): Promise<GuildMember | undefined> {
public async resolveMember({ force = false, fetch = true, cache, id, guildId }: { force?: boolean | undefined; fetch?: boolean; cache?: boolean | undefined; id: string; guildId: string }): Promise<GuildMember | undefined> {
if (force) {
const member = await Result.fromAsync(() => this.rest.get(Routes.guildMember(guildId, id)));
if (member.isOk()) {
Expand All @@ -80,10 +80,12 @@ export class Client extends EventEmitter {
return new GuildMember({ ...JSON.parse(cached_member), id, guild_id: guildId }, this);
}

return this.resolveMember({ id, guildId, force: true, cache: true });
if (fetch) {
return this.resolveMember({ id, guildId, force: true, cache: true });
}
}

public async resolveUser({ force = false, cache, id }: { force?: boolean | undefined; cache?: boolean | undefined; id: string }): Promise<User | undefined> {
public async resolveUser({ force = false, fetch = true, cache, id }: { force?: boolean | undefined; fetch?: boolean; cache?: boolean | undefined; id: string }): Promise<User | undefined> {
if (force) {
const user = await Result.fromAsync(() => this.rest.get(Routes.user(id)));
if (user.isOk()) {
Expand All @@ -98,10 +100,12 @@ export class Client extends EventEmitter {
return new User({ ...JSON.parse(cached_user), id }, this);
}

return this.resolveUser({ id, force: true, cache: true });
if (fetch) {
return this.resolveUser({ id, force: true, cache: true });
}
}

public async resolveGuild({ force = false, cache, id }: { force?: boolean | undefined; cache?: boolean | undefined; id: string }): Promise<Guild | undefined> {
public async resolveGuild({ force = false, fetch = true, cache, id }: { force?: boolean | undefined; fetch?: boolean; cache?: boolean | undefined; id: string }): Promise<Guild | undefined> {
if (force) {
const guild = await Result.fromAsync(() => this.rest.get(Routes.guild(id)));
if (guild.isOk()) {
Expand All @@ -116,7 +120,9 @@ export class Client extends EventEmitter {
return new Guild({ ...JSON.parse(cached_guild), id }, this);
}

return this.resolveGuild({ id, force: true, cache: true });
if (fetch) {
return this.resolveGuild({ id, force: true, cache: true });
}
}

public async resolveRole({ id, guildId }: { id: string; guildId: string }): Promise<Role | undefined> {
Expand All @@ -133,7 +139,7 @@ export class Client extends EventEmitter {
}
}

public async resolveChannel({ force = false, cache, id, guildId }: { force?: boolean | undefined; cache?: boolean | undefined; id: string; guildId: string }): Promise<BaseChannel | undefined> {
public async resolveChannel({ force = false, fetch = true, cache, id, guildId }: { force?: boolean | undefined; fetch?: boolean; cache?: boolean | undefined; id: string; guildId: string }): Promise<BaseChannel | undefined> {
if (force) {
const channel = await Result.fromAsync(() => this.rest.get(Routes.channel(id)));
if (channel.isOk()) {
Expand Down Expand Up @@ -163,7 +169,9 @@ export class Client extends EventEmitter {
}
}

return this.resolveChannel({ id, guildId, force: true, cache: true });
if (fetch) {
return this.resolveChannel({ id, guildId, force: true, cache: true });
}
}

public async sendMessage(options: RESTPostAPIChannelMessageJSONBody, channelId: string): Promise<Message> {
Expand Down

0 comments on commit a2b39e2

Please sign in to comment.