- refactor: rename `RelationshipsManager` > `RelationshipManager`

- feat(RelationshipManager): add `friendCache`, `blockedCache`, `incomingCache`, `outgoingCache`

- feat(ClientApplication): Add `popularCommands`

- deps: Update
This commit is contained in:
March 7th
2022-09-09 23:44:45 +07:00
parent af2a885f2a
commit fb71762d2d
7 changed files with 83 additions and 21 deletions

View File

@@ -14,7 +14,7 @@ const ChannelManager = require('../managers/ChannelManager');
const ClientSettingManager = require('../managers/ClientSettingManager');
const DeveloperPortalManager = require('../managers/DeveloperPortalManager');
const GuildManager = require('../managers/GuildManager');
const RelationshipsManager = require('../managers/RelationshipsManager');
const RelationshipManager = require('../managers/RelationshipManager');
const SessionManager = require('../managers/SessionManager');
const UserManager = require('../managers/UserManager');
const VoiceStateManager = require('../managers/VoiceStateManager');
@@ -142,9 +142,9 @@ class Client extends BaseClient {
// Patch
/**
* All of the relationships {@link User}
* @type {RelationshipsManager}
* @type {RelationshipManager}
*/
this.relationships = new RelationshipsManager(this);
this.relationships = new RelationshipManager(this);
/**
* All of the settings {@link Object}
* @type {ClientSettingManager}

View File

@@ -68,7 +68,7 @@ exports.UserManager = require('./managers/UserManager');
exports.VoiceStateManager = require('./managers/VoiceStateManager');
exports.WebSocketManager = require('./client/websocket/WebSocketManager');
exports.WebSocketShard = require('./client/websocket/WebSocketShard');
exports.RelationshipsManager = require('./managers/RelationshipsManager');
exports.RelationshipManager = require('./managers/RelationshipManager');
// Structures
exports.Activity = require('./structures/Presence').Activity;

View File

@@ -10,7 +10,7 @@ const { RelationshipTypes } = require('../util/Constants');
/**
* Manages API methods for Relationships and stores their cache.
*/
class RelationshipsManager {
class RelationshipManager {
constructor(client, users) {
/**
* The client that instantiated this manager.
@@ -26,6 +26,54 @@ class RelationshipsManager {
this._setup(users);
}
/**
* Get all friends
* @type {Collection<Snowflake, User>}
* @readonly
*/
get friendCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.FRIEND)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Get all blocked users
* @type {Collection<Snowflake, User>}
* @readonly
*/
get blockedCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.BLOCKED)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Get all incoming friend requests
* @type {Collection<Snowflake, User>}
* @readonly
*/
get incomingCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.PENDING_INCOMING)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Get all outgoing friend requests
* @type {Collection<Snowflake, User>}
* @readonly
*/
get outgoingCache() {
const users = this.cache
.filter(value => value === RelationshipTypes.PENDING_OUTGOING)
.map((value, key) => [key, this.client.users.cache.get(key)]);
return new Collection(users);
}
/**
* Return array of cache
* @returns {Array<{id: Snowflake, type: RelationshipTypes}>}
@@ -172,4 +220,4 @@ class RelationshipsManager {
}
}
module.exports = RelationshipsManager;
module.exports = RelationshipManager;

View File

@@ -1,5 +1,6 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const Team = require('./Team');
const Application = require('./interfaces/Application');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
@@ -107,6 +108,17 @@ class ClientApplication extends Application {
this.botPublic ??= null;
}
if ('popular_application_command_ids' in data) {
/**
* List of popular command
* @type {?Collection<Snowflake, ApplicationCommand>}
*/
this.popularCommands = new Collection();
data.popular_application_command_ids.forEach(id => {
this.popularCommands.set(id, this.commands.cache.get(id));
});
}
/**
* The owner of this OAuth application
* @type {?(User|Team)}