From 0324e0f6844882007805221a1abfd990560493b8 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:37:23 +0700 Subject: [PATCH] fix: RelationshipManager cache missing --- src/client/websocket/handlers/READY.js | 4 ++-- src/managers/RelationshipManager.js | 25 +++++++++++++++---------- src/structures/DMChannel.js | 8 +++++++- src/structures/PartialGroupDMChannel.js | 8 +++++++- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/client/websocket/handlers/READY.js b/src/client/websocket/handlers/READY.js index a92c075..522bed4 100644 --- a/src/client/websocket/handlers/READY.js +++ b/src/client/websocket/handlers/READY.js @@ -112,6 +112,8 @@ module.exports = async (client, { d: data }, shard) => { client.user.connectedAccounts = data.connected_accounts ?? []; + client.relationships._setup(data.relationships); + client.user._patchNote(data.notes); const syncTime = Date.now(); @@ -159,7 +161,5 @@ module.exports = async (client, { d: data }, shard) => { }); } - client.relationships._setup(data.relationships); - shard.checkReady(); }; diff --git a/src/managers/RelationshipManager.js b/src/managers/RelationshipManager.js index 01ebab5..bf3f099 100644 --- a/src/managers/RelationshipManager.js +++ b/src/managers/RelationshipManager.js @@ -111,20 +111,25 @@ class RelationshipManager { /** * Obtains a user from Discord, or the user cache if it's already available. - * @param {UserResolvable} user The user to fetch + * @param {UserResolvable} [user] The user to fetch * @param {BaseFetchOptions} [options] Additional options for this fetch - * @returns {Promise} Enums + * @returns {Promise} */ async fetch(user, { force = false } = {}) { - const id = this.resolveId(user); - if (!force) { - const existing = this.cache.get(id); - if (existing && !existing.partial) return existing; + if (user) { + const id = this.resolveId(user); + if (!force) { + const existing = this.cache.get(id); + if (existing && !existing.partial) return existing; + } + const data = await this.client.api.users['@me'].relationships.get(); + await this._setup(data); + return this.cache.get(id); + } else { + const data = await this.client.api.users['@me'].relationships.get(); + await this._setup(data); + return this; } - - const data = await this.client.api.users['@me'].relationships.get(); - await this._setup(data); - return this.cache.get(id); } /** diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index 2a66eaa..f798682 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -115,6 +115,12 @@ class DMChannel extends Channel { * @returns {Promise} */ call(options = {}) { + options = Object.assign( + { + ring: true, + }, + options || {}, + ); return new Promise((resolve, reject) => { if (!this.client.options.patchVoice) { reject( @@ -124,7 +130,7 @@ class DMChannel extends Channel { ), ); } else { - if (options?.ring) { + if (options.ring) { this.client.api.channels(this.id).call.ring.post({ body: { recipients: null, diff --git a/src/structures/PartialGroupDMChannel.js b/src/structures/PartialGroupDMChannel.js index 90117fb..fedcbc8 100644 --- a/src/structures/PartialGroupDMChannel.js +++ b/src/structures/PartialGroupDMChannel.js @@ -311,6 +311,12 @@ class PartialGroupDMChannel extends Channel { * @returns {Promise} */ call(options = {}) { + options = Object.assign( + { + ring: true, + }, + options || {}, + ); return new Promise((resolve, reject) => { if (!this.client.options.patchVoice) { reject( @@ -320,7 +326,7 @@ class PartialGroupDMChannel extends Channel { ), ); } else { - if (options?.ring) { + if (options.ring) { this.client.api.channels(this.id).call.ring.post({ body: { recipients: null,