feat(RelationshipsManager): new cancelFriendRequest method

Extends (add Typings)
This commit is contained in:
March 7th 2022-07-19 20:27:32 +07:00
parent baa2900428
commit f7db2384b9
2 changed files with 23 additions and 17 deletions

View File

@ -63,7 +63,7 @@ class RelationshipsManager {
* 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<User>} * @returns {Promise<RelationshipTypes>} Enums
*/ */
async fetch(user, { force = false } = {}) { async fetch(user, { force = false } = {}) {
const id = this.resolveId(user); const id = this.resolveId(user);
@ -81,28 +81,26 @@ class RelationshipsManager {
/** /**
* Deletes a friend relationship with a client user. * Deletes a friend relationship with a client user.
* @param {User} user Target * @param {UserResolvable} user Target
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
async deleteFriend(user) { deleteFriend(user) {
const id = this.resolveId(user); const id = this.resolveId(user);
// Check if already friends // Check if already friends
if (this.cache.get(id) !== RelationshipTypes.FRIEND) return false; if (this.cache.get(id) !== RelationshipTypes.FRIEND) return false;
await this.client.api.users['@me'].relationships[id].delete(); // 204 status and no data return this.__cancel(id);
return true;
} }
/** /**
* Deletes a blocked relationship with a client user. * Deletes a blocked relationship with a client user.
* @param {User} user Target * @param {UserResolvable} user Target
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
async deleteBlocked(user) { deleteBlocked(user) {
const id = this.resolveId(user); const id = this.resolveId(user);
// Check if already blocked // Check if already blocked
if (this.cache.get(id) !== RelationshipTypes.BLOCKED) return false; if (this.cache.get(id) !== RelationshipTypes.BLOCKED) return false;
await this.client.api.users['@me'].relationships[id].delete(); // 204 status and no data return this.__cancel(id);
return true;
} }
/** /**
@ -123,10 +121,16 @@ class RelationshipsManager {
/** /**
* Cancels a friend request. * 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<boolean>} * @returns {Promise<boolean>}
*/ */
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(); await this.client.api.users['@me'].relationships[id].delete();
return true; return true;
} }

14
typings/index.d.ts vendored
View File

@ -3916,12 +3916,14 @@ export class RelationshipsManager {
private constructor(client: Client, users?: object[]); private constructor(client: Client, users?: object[]);
public cache: Collection<Snowflake, RelationshipTypes>; public cache: Collection<Snowflake, RelationshipTypes>;
public client: Client; public client: Client;
public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<User>; public fetch(user: UserResolvable, options?: BaseFetchOptions): Promise<RelationshipTypes>;
public deleteFriend(user: UserResolvable): Promise<User>; public deleteFriend(user: UserResolvable): Promise<boolean>;
public deleteBlocked(user: UserResolvable): Promise<User>; public deleteBlocked(user: UserResolvable): Promise<boolean>;
public sendFriendRequest(username: string, discriminator: number): Promise<User>; public sendFriendRequest(username: string, discriminator: number): Promise<boolean>;
public addFriend(user: UserResolvable): Promise<User>; public cancelFriendRequest(user: UserResolvable): Promise<boolean>;
public addBlocked(user: UserResolvable): Promise<User>; public addFriend(user: UserResolvable): Promise<boolean>;
public addBlocked(user: UserResolvable): Promise<boolean>;
private __cancel(id: Snowflake): Promise<boolean>;
} }
export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, typeof VoiceState> { export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, typeof VoiceState> {