feat: bypass cache check with forceFetch param (#4592)

This commit is contained in:
Carter
2020-08-12 13:23:04 -06:00
committed by GitHub
parent 0225851e40
commit 290938bf80
11 changed files with 84 additions and 45 deletions

View File

@@ -90,10 +90,11 @@ class Channel extends Base {
/**
* Fetches this channel.
* @param {boolean} [force=false] Whether to skip the cache check and request the API
* @returns {Promise<Channel>}
*/
fetch() {
return this.client.channels.fetch(this.id, true);
fetch(force = false) {
return this.client.channels.fetch(this.id, true, force);
}
static create(client, data, guild) {

View File

@@ -61,10 +61,11 @@ class DMChannel extends Channel {
/**
* Fetch this DMChannel.
* @param {boolean} [force=false] Whether to skip the cache check and request the API
* @returns {Promise<DMChannel>}
*/
fetch() {
return this.recipient.createDM();
fetch(force = false) {
return this.recipient.createDM(force);
}
/**

View File

@@ -373,10 +373,11 @@ class GuildMember extends Base {
/**
* Fetches this GuildMember.
* @param {boolean} [force=false] Whether to skip the cache check and request the API
* @returns {Promise<GuildMember>}
*/
fetch() {
return this.guild.members.fetch(this.id, true);
fetch(force = false) {
return this.guild.members.fetch({ user: this.id, cache: true, force });
}
/**

View File

@@ -547,10 +547,11 @@ class Message extends Base {
/**
* Fetch this message.
* @param {boolean} [force=false] Whether to skip the cache check and request the API
* @returns {Promise<Message>}
*/
fetch() {
return this.channel.messages.fetch(this.id, true);
fetch(force = false) {
return this.channel.messages.fetch(this.id, true, force);
}
/**

View File

@@ -222,11 +222,15 @@ class User extends Base {
/**
* Creates a DM channel between the client and the user.
* @param {boolean} [force=false] Whether to skip the cache check and request the API
* @returns {Promise<DMChannel>}
*/
async createDM() {
const { dmChannel } = this;
if (dmChannel && !dmChannel.partial) return dmChannel;
async createDM(force = false) {
if (!force) {
const { dmChannel } = this;
if (dmChannel && !dmChannel.partial) return dmChannel;
}
const data = await this.client.api.users(this.client.user.id).channels.post({
data: {
recipient_id: this.id,
@@ -265,10 +269,11 @@ class User extends Base {
/**
* Fetches this user's flags.
* @param {boolean} [force=false] Whether to skip the cache check and request the AP
* @returns {Promise<UserFlags>}
*/
async fetchFlags() {
if (this.flags) return this.flags;
async fetchFlags(force = false) {
if (this.flags && !force) return this.flags;
const data = await this.client.api.users(this.id).get();
this._patch(data);
return this.flags;
@@ -276,10 +281,11 @@ class User extends Base {
/**
* Fetches this user.
* @param {boolean} [force=false] Whether to skip the cache check and request the AP
* @returns {Promise<User>}
*/
fetch() {
return this.client.users.fetch(this.id, true);
fetch(force = false) {
return this.client.users.fetch(this.id, true, force);
}
/**