@@ -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}
|
||||
|
@@ -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;
|
||||
|
@@ -1,11 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { TypeError, Error } = require('../errors');
|
||||
const GuildBan = require('../structures/GuildBan');
|
||||
const { GuildMember } = require('../structures/GuildMember');
|
||||
|
||||
let deprecationEmittedForDays = false;
|
||||
|
||||
/**
|
||||
* Manages API methods for GuildBans and stores their cache.
|
||||
* @extends {CachedManager}
|
||||
@@ -126,6 +129,9 @@ class GuildBanManager extends CachedManager {
|
||||
* Options used to ban a user from a guild.
|
||||
* @typedef {Object} BanOptions
|
||||
* @property {number} [days=0] Number of days of messages to delete, must be between 0 and 7, inclusive
|
||||
* <warn>This property is deprecated. Use `deleteMessageSeconds` instead.</warn>
|
||||
* @property {number} [deleteMessageSeconds=0] Number of seconds of messages to delete,
|
||||
* must be between 0 and 604800 (7 days), inclusive
|
||||
* @property {string} [reason] The reason for the ban
|
||||
*/
|
||||
|
||||
@@ -142,15 +148,30 @@ class GuildBanManager extends CachedManager {
|
||||
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async create(user, options = { days: 0 }) {
|
||||
async create(user, options = {}) {
|
||||
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
||||
const id = this.client.users.resolveId(user);
|
||||
if (!id) throw new Error('BAN_RESOLVE_ID', true);
|
||||
|
||||
if (typeof options.days !== 'undefined' && !deprecationEmittedForDays) {
|
||||
process.emitWarning(
|
||||
'The days option for GuildBanManager#create() is deprecated. Use the deleteMessageSeconds option instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForDays = true;
|
||||
}
|
||||
|
||||
await this.client.api
|
||||
.guilds(this.guild.id)
|
||||
.bans(id)
|
||||
.put({
|
||||
data: { delete_message_days: options.days },
|
||||
data: {
|
||||
delete_message_seconds:
|
||||
typeof options.deleteMessageSeconds !== 'undefined'
|
||||
? options.deleteMessageSeconds
|
||||
: (options.days ?? 0) * 24 * 60 * 60,
|
||||
},
|
||||
reason: options.reason,
|
||||
});
|
||||
if (user instanceof GuildMember) return user;
|
||||
|
@@ -394,7 +394,7 @@ class GuildMemberManager extends CachedManager {
|
||||
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
ban(user, options = { days: 0 }) {
|
||||
ban(user, options) {
|
||||
return this.guild.bans.create(user, options);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
@@ -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)}
|
||||
|
@@ -465,8 +465,8 @@ class GuildMember extends Base {
|
||||
* @param {BanOptions} [options] Options for the ban
|
||||
* @returns {Promise<GuildMember>}
|
||||
* @example
|
||||
* // ban a guild member
|
||||
* guildMember.ban({ days: 7, reason: 'They deserved it' })
|
||||
* // Ban a guild member, deleting a week's worth of messages
|
||||
* guildMember.ban({ deleteMessageSeconds: 60 * 60 * 24 * 7, reason: 'They deserved it' })
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
|
@@ -40,6 +40,7 @@ class Intents extends BitField {}
|
||||
* * `DIRECT_MESSAGES`
|
||||
* * `DIRECT_MESSAGE_REACTIONS`
|
||||
* * `DIRECT_MESSAGE_TYPING`
|
||||
* * `MESSAGE_CONTENT`
|
||||
* * `GUILD_SCHEDULED_EVENTS`
|
||||
* @type {Object}
|
||||
* @see {@link https://discord.com/developers/docs/topics/gateway#list-of-intents}
|
||||
@@ -60,6 +61,7 @@ Intents.FLAGS = {
|
||||
DIRECT_MESSAGES: 1 << 12,
|
||||
DIRECT_MESSAGE_REACTIONS: 1 << 13,
|
||||
DIRECT_MESSAGE_TYPING: 1 << 14,
|
||||
MESSAGE_CONTENT: 1 << 15,
|
||||
GUILD_SCHEDULED_EVENTS: 1 << 16,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user