fix: RelationshipManager cache missing

This commit is contained in:
March 7th 2022-10-25 12:37:23 +07:00
parent 1c0aefd7ec
commit 0324e0f684
4 changed files with 31 additions and 14 deletions

View File

@ -112,6 +112,8 @@ module.exports = async (client, { d: data }, shard) => {
client.user.connectedAccounts = data.connected_accounts ?? []; client.user.connectedAccounts = data.connected_accounts ?? [];
client.relationships._setup(data.relationships);
client.user._patchNote(data.notes); client.user._patchNote(data.notes);
const syncTime = Date.now(); const syncTime = Date.now();
@ -159,7 +161,5 @@ module.exports = async (client, { d: data }, shard) => {
}); });
} }
client.relationships._setup(data.relationships);
shard.checkReady(); shard.checkReady();
}; };

View File

@ -111,20 +111,25 @@ class RelationshipManager {
/** /**
* Obtains a user from Discord, or the user cache if it's already available. * 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 * @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<RelationshipTypes>} Enums * @returns {Promise<RelationshipTypes|RelationshipManager>}
*/ */
async fetch(user, { force = false } = {}) { async fetch(user, { force = false } = {}) {
const id = this.resolveId(user); if (user) {
if (!force) { const id = this.resolveId(user);
const existing = this.cache.get(id); if (!force) {
if (existing && !existing.partial) return existing; 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);
} }
/** /**

View File

@ -115,6 +115,12 @@ class DMChannel extends Channel {
* @returns {Promise<VoiceConnection>} * @returns {Promise<VoiceConnection>}
*/ */
call(options = {}) { call(options = {}) {
options = Object.assign(
{
ring: true,
},
options || {},
);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.client.options.patchVoice) { if (!this.client.options.patchVoice) {
reject( reject(
@ -124,7 +130,7 @@ class DMChannel extends Channel {
), ),
); );
} else { } else {
if (options?.ring) { if (options.ring) {
this.client.api.channels(this.id).call.ring.post({ this.client.api.channels(this.id).call.ring.post({
body: { body: {
recipients: null, recipients: null,

View File

@ -311,6 +311,12 @@ class PartialGroupDMChannel extends Channel {
* @returns {Promise<VoiceConnection>} * @returns {Promise<VoiceConnection>}
*/ */
call(options = {}) { call(options = {}) {
options = Object.assign(
{
ring: true,
},
options || {},
);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.client.options.patchVoice) { if (!this.client.options.patchVoice) {
reject( reject(
@ -320,7 +326,7 @@ class PartialGroupDMChannel extends Channel {
), ),
); );
} else { } else {
if (options?.ring) { if (options.ring) {
this.client.api.channels(this.id).call.ring.post({ this.client.api.channels(this.id).call.ring.post({
body: { body: {
recipients: null, recipients: null,