feat: User#mutualFriends

This commit is contained in:
March 7th 2022-12-13 14:55:51 +07:00
parent ad8bed71c8
commit 6ef8970a1e
2 changed files with 20 additions and 1 deletions

View File

@ -178,7 +178,25 @@ class User extends Base {
}
/**
* Check relationship status
* Get all mutual friends (Client -> User)
* @type {Promise<Collection<Snowflake, User>>}
* @readonly
*/
get mutualFriends() {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async resolve => {
const all = new Collection();
if (this.bot || this.client.user.id === this.id) return resolve(all);
const data = await this.client.api.users(this.id).relationships.get();
for (const u of data) {
all.set(u.id, this.client.users._add(u));
}
return resolve(all);
});
}
/**
* Check relationship status (Client -> User)
* @type {RelationshipTypes}
* @readonly
*/

1
typings/index.d.ts vendored
View File

@ -3044,6 +3044,7 @@ export class User extends PartialTextBasedChannel(Base) {
public readonly premiumGuildSince: Date;
public readonly bio: string | null;
public readonly mutualGuilds: Collection<Snowflake, object>;
public readonly mutualFriends: Promise<Collection<Snowflake, User>>;
public readonly voice: VoiceState;
public avatarURL(options?: ImageURLOptions): string | null;
public bannerURL(options?: ImageURLOptions): string | null;