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

@@ -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);
}
/**