From f7db2384b9e57134e3d4105918db74cfee656216 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Tue, 19 Jul 2022 20:27:32 +0700 Subject: [PATCH] feat(RelationshipsManager): new `cancelFriendRequest` method Extends (add Typings) --- src/managers/RelationshipsManager.js | 26 +++++++++++++++----------- typings/index.d.ts | 14 ++++++++------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/managers/RelationshipsManager.js b/src/managers/RelationshipsManager.js index de5e530..1905bba 100644 --- a/src/managers/RelationshipsManager.js +++ b/src/managers/RelationshipsManager.js @@ -63,7 +63,7 @@ class RelationshipsManager { * Obtains a user from Discord, or the user cache if it's already available. * @param {UserResolvable} user The user to fetch * @param {BaseFetchOptions} [options] Additional options for this fetch - * @returns {Promise} + * @returns {Promise} Enums */ async fetch(user, { force = false } = {}) { const id = this.resolveId(user); @@ -81,28 +81,26 @@ class RelationshipsManager { /** * Deletes a friend relationship with a client user. - * @param {User} user Target + * @param {UserResolvable} user Target * @returns {Promise} */ - async deleteFriend(user) { + deleteFriend(user) { const id = this.resolveId(user); // Check if already friends if (this.cache.get(id) !== RelationshipTypes.FRIEND) return false; - await this.client.api.users['@me'].relationships[id].delete(); // 204 status and no data - return true; + return this.__cancel(id); } /** * Deletes a blocked relationship with a client user. - * @param {User} user Target + * @param {UserResolvable} user Target * @returns {Promise} */ - async deleteBlocked(user) { + deleteBlocked(user) { const id = this.resolveId(user); // Check if already blocked if (this.cache.get(id) !== RelationshipTypes.BLOCKED) return false; - await this.client.api.users['@me'].relationships[id].delete(); // 204 status and no data - return true; + return this.__cancel(id); } /** @@ -123,10 +121,16 @@ class RelationshipsManager { /** * Cancels a friend request. - * @param {Snowflake} snowflake Snowflake of the user you want to delete + * @param {UserResolvable} user the user you want to delete * @returns {Promise} */ - async cancelFriendRequest(id) { + cancelFriendRequest(user) { + const id = this.resolveId(user); + if (this.cache.get(id) !== RelationshipTypes.OUTGOING_REQUEST) return false; + return this.__cancel(id); + } + + async __cancel(id) { await this.client.api.users['@me'].relationships[id].delete(); return true; } diff --git a/typings/index.d.ts b/typings/index.d.ts index ae796fa..4a8a462 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3916,12 +3916,14 @@ export class RelationshipsManager { private constructor(client: Client, users?: object[]); public cache: Collection; public client: Client; - public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise; - public deleteFriend(user: UserResolvable): Promise; - public deleteBlocked(user: UserResolvable): Promise; - public sendFriendRequest(username: string, discriminator: number): Promise; - public addFriend(user: UserResolvable): Promise; - public addBlocked(user: UserResolvable): Promise; + public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise; + public deleteFriend(user: UserResolvable): Promise; + public deleteBlocked(user: UserResolvable): Promise; + public sendFriendRequest(username: string, discriminator: number): Promise; + public cancelFriendRequest(user: UserResolvable): Promise; + public addFriend(user: UserResolvable): Promise; + public addBlocked(user: UserResolvable): Promise; + private __cancel(id: Snowflake): Promise; } export class VoiceStateManager extends CachedManager {