refactor(Managers): rename add to _add (#6060)

This commit is contained in:
1Computer1
2021-07-08 06:34:45 -04:00
committed by GitHub
parent 28b5ffb4d6
commit 9cd5e7ed61
72 changed files with 157 additions and 159 deletions

View File

@@ -26,7 +26,7 @@ class GenericAction {
getPayload(data, manager, id, partialType, cache) { getPayload(data, manager, id, partialType, cache) {
const existing = manager.cache.get(id); const existing = manager.cache.get(id);
if (!existing && this.client.options.partials.includes(partialType)) { if (!existing && this.client.options.partials.includes(partialType)) {
return manager.add(data, cache); return manager._add(data, cache);
} }
return existing; return existing;
} }
@@ -93,9 +93,9 @@ class GenericAction {
if (data.guild_id && data.member?.user) { if (data.guild_id && data.member?.user) {
const guild = this.client.guilds.cache.get(data.guild_id); const guild = this.client.guilds.cache.get(data.guild_id);
if (guild) { if (guild) {
return guild.members.add(data.member).user; return guild.members._add(data.member).user;
} else { } else {
return this.client.users.add(data.member.user); return this.client.users._add(data.member.user);
} }
} }
return this.getUser(data); return this.getUser(data);

View File

@@ -7,7 +7,7 @@ class ChannelCreateAction extends Action {
handle(data) { handle(data) {
const client = this.client; const client = this.client;
const existing = client.channels.cache.has(data.id); const existing = client.channels.cache.has(data.id);
const channel = client.channels.add(data); const channel = client.channels._add(data);
if (!existing && channel) { if (!existing && channel) {
/** /**
* Emitted whenever a guild channel is created. * Emitted whenever a guild channel is created.

View File

@@ -15,7 +15,7 @@ class ChannelDeleteAction extends Action {
const channel = client.channels.cache.get(data.id); const channel = client.channels.cache.get(data.id);
if (channel) { if (channel) {
client.channels.remove(channel.id); client.channels._remove(channel.id);
channel.deleted = true; channel.deleted = true;
if (channel.messages && !(channel instanceof DMChannel)) { if (channel.messages && !(channel instanceof DMChannel)) {
for (const message of channel.messages.cache.values()) { for (const message of channel.messages.cache.values()) {

View File

@@ -25,7 +25,7 @@ class ChannelUpdateAction extends Action {
updated: channel, updated: channel,
}; };
} else { } else {
client.channels.add(data); client.channels._add(data);
} }
return {}; return {};

View File

@@ -13,7 +13,7 @@ class GuildBanAdd extends Action {
* @event Client#guildBanAdd * @event Client#guildBanAdd
* @param {GuildBan} ban The ban that occurred * @param {GuildBan} ban The ban that occurred
*/ */
if (guild) client.emit(Events.GUILD_BAN_ADD, guild.bans.add(data)); if (guild) client.emit(Events.GUILD_BAN_ADD, guild.bans._add(data));
} }
} }

View File

@@ -36,7 +36,7 @@ class GuildDeleteAction extends Action {
}; };
} }
for (const channel of guild.channels.cache.values()) this.client.channels.remove(channel.id); for (const channel of guild.channels.cache.values()) this.client.channels._remove(channel.id);
client.voice.adapters.get(data.id)?.destroy(); client.voice.adapters.get(data.id)?.destroy();
// Delete guild // Delete guild

View File

@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
class GuildEmojiCreateAction extends Action { class GuildEmojiCreateAction extends Action {
handle(guild, createdEmoji) { handle(guild, createdEmoji) {
const already = guild.emojis.cache.has(createdEmoji.id); const already = guild.emojis.cache.has(createdEmoji.id);
const emoji = guild.emojis.add(createdEmoji); const emoji = guild.emojis._add(createdEmoji);
/** /**
* Emitted whenever a custom emoji is created in a guild. * Emitted whenever a custom emoji is created in a guild.
* @event Client#emojiCreate * @event Client#emojiCreate

View File

@@ -9,7 +9,7 @@ class GuildMemberUpdateAction extends Action {
if (data.user.username) { if (data.user.username) {
const user = client.users.cache.get(data.user.id); const user = client.users.cache.get(data.user.id);
if (!user) { if (!user) {
client.users.add(data.user); client.users._add(data.user);
} else if (!user.equals(data.user)) { } else if (!user.equals(data.user)) {
client.actions.UserUpdate.handle(data.user); client.actions.UserUpdate.handle(data.user);
} }
@@ -29,7 +29,7 @@ class GuildMemberUpdateAction extends Action {
*/ */
if (shard.status === Status.READY && !member.equals(old)) client.emit(Events.GUILD_MEMBER_UPDATE, old, member); if (shard.status === Status.READY && !member.equals(old)) client.emit(Events.GUILD_MEMBER_UPDATE, old, member);
} else { } else {
const newMember = guild.members.add(data); const newMember = guild.members._add(data);
/** /**
* Emitted whenever a member becomes available in a large guild. * Emitted whenever a member becomes available in a large guild.
* @event Client#guildMemberAvailable * @event Client#guildMemberAvailable

View File

@@ -10,7 +10,7 @@ class GuildRoleCreate extends Action {
let role; let role;
if (guild) { if (guild) {
const already = guild.roles.cache.has(data.role.id); const already = guild.roles.cache.has(data.role.id);
role = guild.roles.add(data.role); role = guild.roles._add(data.role);
/** /**
* Emitted whenever a role is created. * Emitted whenever a role is created.
* @event Client#roleCreate * @event Client#roleCreate

View File

@@ -11,7 +11,7 @@ class InviteCreateAction extends Action {
if (!channel) return false; if (!channel) return false;
const inviteData = Object.assign(data, { channel, guild }); const inviteData = Object.assign(data, { channel, guild });
const invite = guild.invites.add(inviteData); const invite = guild.invites._add(inviteData);
/** /**
* Emitted when an invite is created. * Emitted when an invite is created.

View File

@@ -12,7 +12,7 @@ class MessageCreateAction extends Action {
if (channel) { if (channel) {
const existing = channel.messages.cache.get(data.id); const existing = channel.messages.cache.get(data.id);
if (existing) return { message: existing }; if (existing) return { message: existing };
const message = channel.messages.add(data); const message = channel.messages._add(data);
channel.lastMessageId = data.id; channel.lastMessageId = data.id;
/** /**

View File

@@ -33,7 +33,7 @@ class MessageReactionAdd extends Action {
if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false; if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false;
const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name); const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name);
if (existing?.users.cache.has(user.id)) return { message, reaction: existing, user }; if (existing?.users.cache.has(user.id)) return { message, reaction: existing, user };
const reaction = message.reactions.add({ const reaction = message.reactions._add({
emoji: data.emoji, emoji: data.emoji,
count: message.partial ? null : 0, count: message.partial ? null : 0,
me: user.id === this.client.user.id, me: user.id === this.client.user.id,

View File

@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
class PresenceUpdateAction extends Action { class PresenceUpdateAction extends Action {
handle(data) { handle(data) {
let user = this.client.users.cache.get(data.user.id); let user = this.client.users.cache.get(data.user.id);
if (!user && data.user?.username) user = this.client.users.add(data.user); if (!user && data.user?.username) user = this.client.users._add(data.user);
if (!user) return; if (!user) return;
if (data.user?.username) { if (data.user?.username) {
@@ -19,14 +19,14 @@ class PresenceUpdateAction extends Action {
const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null; const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
let member = guild.members.cache.get(user.id); let member = guild.members.cache.get(user.id);
if (!member && data.status !== 'offline') { if (!member && data.status !== 'offline') {
member = guild.members.add({ member = guild.members._add({
user, user,
deaf: false, deaf: false,
mute: false, mute: false,
}); });
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, member); this.client.emit(Events.GUILD_MEMBER_AVAILABLE, member);
} }
guild.presences.add(Object.assign(data, { guild })); guild.presences._add(Object.assign(data, { guild }));
if (this.client.listenerCount(Events.PRESENCE_UPDATE) && member && !member.presence.equals(oldPresence)) { if (this.client.listenerCount(Events.PRESENCE_UPDATE) && member && !member.presence.equals(oldPresence)) {
/** /**
* Emitted whenever a guild member's presence (e.g. status, activity) is changed. * Emitted whenever a guild member's presence (e.g. status, activity) is changed.

View File

@@ -9,7 +9,7 @@ class StageInstanceCreateAction extends Action {
const channel = this.getChannel(data); const channel = this.getChannel(data);
if (channel) { if (channel) {
const stageInstance = channel.guild.stageInstances.add(data); const stageInstance = channel.guild.stageInstances._add(data);
/** /**
* Emitted whenever a stage instance is created. * Emitted whenever a stage instance is created.

View File

@@ -9,7 +9,7 @@ class StageInstanceDeleteAction extends Action {
const channel = this.getChannel(data); const channel = this.getChannel(data);
if (channel) { if (channel) {
const stageInstance = channel.guild.stageInstances.add(data); const stageInstance = channel.guild.stageInstances._add(data);
if (stageInstance) { if (stageInstance) {
channel.guild.stageInstances.cache.delete(stageInstance.id); channel.guild.stageInstances.cache.delete(stageInstance.id);
stageInstance.deleted = true; stageInstance.deleted = true;

View File

@@ -10,7 +10,7 @@ class StageInstanceUpdateAction extends Action {
if (channel) { if (channel) {
const oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone() ?? null; const oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone() ?? null;
const newStageInstance = channel.guild.stageInstances.add(data); const newStageInstance = channel.guild.stageInstances._add(data);
/** /**
* Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level * Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level

View File

@@ -7,7 +7,7 @@ class ThreadCreateAction extends Action {
handle(data) { handle(data) {
const client = this.client; const client = this.client;
const existing = client.channels.cache.has(data.id); const existing = client.channels.cache.has(data.id);
const thread = client.channels.add(data); const thread = client.channels._add(data);
if (!existing && thread) { if (!existing && thread) {
/** /**
* Emitted whenever a thread is created or when the client user is added to a thread. * Emitted whenever a thread is created or when the client user is added to a thread.

View File

@@ -9,7 +9,7 @@ class ThreadDeleteAction extends Action {
const thread = client.channels.cache.get(data.id); const thread = client.channels.cache.get(data.id);
if (thread) { if (thread) {
client.channels.remove(thread.id); client.channels._remove(thread.id);
thread.deleted = true; thread.deleted = true;
for (const message of thread.messages.cache.values()) { for (const message of thread.messages.cache.values()) {
message.deleted = true; message.deleted = true;

View File

@@ -23,7 +23,7 @@ class ThreadListSyncAction extends Action {
} }
const syncedThreads = data.threads.reduce((coll, rawThread) => { const syncedThreads = data.threads.reduce((coll, rawThread) => {
const thread = client.channels.add(rawThread); const thread = client.channels._add(rawThread);
return coll.set(thread.id, thread); return coll.set(thread.id, thread);
}, new Collection()); }, new Collection());
@@ -50,7 +50,7 @@ class ThreadListSyncAction extends Action {
removeStale(channel) { removeStale(channel) {
channel.threads?.cache.forEach(thread => { channel.threads?.cache.forEach(thread => {
if (!thread.archived) { if (!thread.archived) {
this.client.channels.remove(thread.id); this.client.channels._remove(thread.id);
} }
}); });
} }

View File

@@ -13,14 +13,14 @@ class VoiceStateUpdate extends Action {
const oldState = const oldState =
guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id }); guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id });
const newState = guild.voiceStates.add(data); const newState = guild.voiceStates._add(data);
// Get the member // Get the member
let member = guild.members.cache.get(data.user_id); let member = guild.members.cache.get(data.user_id);
if (member && data.member) { if (member && data.member) {
member._patch(data.member); member._patch(data.member);
} else if (data.member?.user && data.member.joined_at) { } else if (data.member?.user && data.member.joined_at) {
member = guild.members.add(data.member); member = guild.members._add(data.member);
} }
// Emit event // Emit event

View File

@@ -8,9 +8,9 @@ module.exports = (client, { d: data }) => {
if (data.guild_id) { if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id); const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return; if (!guild) return;
command = guild.commands.add(data); command = guild.commands._add(data);
} else { } else {
command = client.application.commands.add(data); command = client.application.commands._add(data);
} }
/** /**

View File

@@ -8,10 +8,10 @@ module.exports = (client, { d: data }) => {
if (data.guild_id) { if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id); const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return; if (!guild) return;
command = guild.commands.add(data); command = guild.commands._add(data);
guild.commands.cache.delete(data.id); guild.commands.cache.delete(data.id);
} else { } else {
command = client.application.commands.add(data); command = client.application.commands._add(data);
client.application.commands.cache.delete(data.id); client.application.commands.cache.delete(data.id);
} }

View File

@@ -10,10 +10,10 @@ module.exports = (client, { d: data }) => {
const guild = client.guilds.cache.get(data.guild_id); const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return; if (!guild) return;
oldCommand = guild.commands.cache.get(data.id)?._clone() ?? null; oldCommand = guild.commands.cache.get(data.id)?._clone() ?? null;
newCommand = guild.commands.add(data); newCommand = guild.commands._add(data);
} else { } else {
oldCommand = client.application.commands.cache.get(data.id)?._clone() ?? null; oldCommand = client.application.commands.cache.get(data.id)?._clone() ?? null;
newCommand = client.application.commands.add(data); newCommand = client.application.commands._add(data);
} }
/** /**

View File

@@ -12,7 +12,7 @@ module.exports = (client, { d: data }, shard) => {
} else { } else {
// A new guild // A new guild
data.shardId = shard.id; data.shardId = shard.id;
guild = client.guilds.add(data); guild = client.guilds._add(data);
if (client.ws.status === Status.READY) { if (client.ws.status === Status.READY) {
/** /**
* Emitted whenever the client joins a guild. * Emitted whenever the client joins a guild.

View File

@@ -8,9 +8,9 @@ module.exports = (client, { d: data }) => {
if (!guild) return; if (!guild) return;
const members = new Collection(); const members = new Collection();
for (const member of data.members) members.set(member.user.id, guild.members.add(member)); for (const member of data.members) members.set(member.user.id, guild.members._add(member));
if (data.presences) { if (data.presences) {
for (const presence of data.presences) guild.presences.add(Object.assign(presence, { guild })); for (const presence of data.presences) guild.presences._add(Object.assign(presence, { guild }));
} }
/** /**
* Emitted whenever a chunk of guild members is received (all members come from the same guild). * Emitted whenever a chunk of guild members is received (all members come from the same guild).

View File

@@ -6,7 +6,7 @@ module.exports = (client, { d: data }, shard) => {
const guild = client.guilds.cache.get(data.guild_id); const guild = client.guilds.cache.get(data.guild_id);
if (guild) { if (guild) {
guild.memberCount++; guild.memberCount++;
const member = guild.members.add(data); const member = guild.members._add(data);
if (shard.status === Status.READY) { if (shard.status === Status.READY) {
/** /**
* Emitted whenever a user joins a guild. * Emitted whenever a user joins a guild.

View File

@@ -14,7 +14,7 @@ module.exports = (client, { d: data }, shard) => {
for (const guild of data.guilds) { for (const guild of data.guilds) {
guild.shardId = shard.id; guild.shardId = shard.id;
client.guilds.add(guild); client.guilds._add(guild);
} }
if (client.application) { if (client.application) {

View File

@@ -27,8 +27,8 @@ class ApplicationCommandManager extends CachedManager {
* @name ApplicationCommandManager#cache * @name ApplicationCommandManager#cache
*/ */
add(data, cache, guildId) { _add(data, cache, guildId) {
return super.add(data, cache, { extras: [this.guild, guildId] }); return super._add(data, cache, { extras: [this.guild, guildId] });
} }
/** /**
@@ -90,11 +90,11 @@ class ApplicationCommandManager extends CachedManager {
if (existing) return existing; if (existing) return existing;
} }
const command = await this.commandPath({ id, guildId }).get(); const command = await this.commandPath({ id, guildId }).get();
return this.add(command, cache); return this._add(command, cache);
} }
const data = await this.commandPath({ guildId }).get(); const data = await this.commandPath({ guildId }).get();
return data.reduce((coll, command) => coll.set(command.id, this.add(command, cache, guildId)), new Collection()); return data.reduce((coll, command) => coll.set(command.id, this._add(command, cache, guildId)), new Collection());
} }
/** /**
@@ -116,7 +116,7 @@ class ApplicationCommandManager extends CachedManager {
const data = await this.commandPath({ guildId }).post({ const data = await this.commandPath({ guildId }).post({
data: this.constructor.transformCommand(command), data: this.constructor.transformCommand(command),
}); });
return this.add(data, undefined, guildId); return this._add(data, undefined, guildId);
} }
/** /**
@@ -146,7 +146,7 @@ class ApplicationCommandManager extends CachedManager {
data: commands.map(c => this.constructor.transformCommand(c)), data: commands.map(c => this.constructor.transformCommand(c)),
}); });
return data.reduce( return data.reduce(
(coll, command) => coll.set(command.id, this.add(command, undefined, guildId)), (coll, command) => coll.set(command.id, this._add(command, undefined, guildId)),
new Collection(), new Collection(),
); );
} }
@@ -171,7 +171,7 @@ class ApplicationCommandManager extends CachedManager {
if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable'); if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
const patched = await this.commandPath({ id, guildId }).patch({ data: this.constructor.transformCommand(data) }); const patched = await this.commandPath({ id, guildId }).patch({ data: this.constructor.transformCommand(data) });
return this.add(patched, undefined, guildId); return this._add(patched, undefined, guildId);
} }
/** /**

View File

@@ -15,7 +15,7 @@ class CachedManager extends DataManager {
if (iterable) { if (iterable) {
for (const item of iterable) { for (const item of iterable) {
this.add(item); this._add(item);
} }
} }
} }
@@ -29,7 +29,7 @@ class CachedManager extends DataManager {
return this._cache; return this._cache;
} }
add(data, cache = true, { id, extras = [] } = {}) { _add(data, cache = true, { id, extras = [] } = {}) {
const existing = this.cache.get(id ?? data.id); const existing = this.cache.get(id ?? data.id);
if (cache) existing?._patch(data); if (cache) existing?._patch(data);
if (existing) return existing; if (existing) return existing;

View File

@@ -19,13 +19,13 @@ class ChannelManager extends CachedManager {
* @name ChannelManager#cache * @name ChannelManager#cache
*/ */
add(data, guild, cache = true, allowUnknownGuild = false) { _add(data, guild, cache = true, allowUnknownGuild = false) {
const existing = this.cache.get(data.id); const existing = this.cache.get(data.id);
if (existing) { if (existing) {
if (cache) existing._patch(data); if (cache) existing._patch(data);
guild?.channels?.add(existing); guild?.channels?._add(existing);
if (ThreadChannelTypes.includes(existing.type)) { if (ThreadChannelTypes.includes(existing.type)) {
existing.parent?.threads?.add(existing); existing.parent?.threads?._add(existing);
} }
return existing; return existing;
} }
@@ -42,7 +42,7 @@ class ChannelManager extends CachedManager {
return channel; return channel;
} }
remove(id) { _remove(id) {
const channel = this.cache.get(id); const channel = this.cache.get(id);
channel?.guild?.channels.cache.delete(id); channel?.guild?.channels.cache.delete(id);
channel?.parent?.threads?.cache.delete(id); channel?.parent?.threads?.cache.delete(id);
@@ -99,7 +99,7 @@ class ChannelManager extends CachedManager {
} }
const data = await this.client.api.channels(id).get(); const data = await this.client.api.channels(id).get();
return this.add(data, null, cache, allowUnknownGuild); return this._add(data, null, cache, allowUnknownGuild);
} }
} }

View File

@@ -27,8 +27,8 @@ class GuildBanManager extends CachedManager {
* @name GuildBanManager#cache * @name GuildBanManager#cache
*/ */
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { id: data.user.id, extras: [this.guild] }); return super._add(data, cache, { id: data.user.id, extras: [this.guild] });
} }
/** /**
@@ -110,12 +110,12 @@ class GuildBanManager extends CachedManager {
} }
const data = await this.client.api.guilds(this.guild.id).bans(user).get(); const data = await this.client.api.guilds(this.guild.id).bans(user).get();
return this.add(data, cache); return this._add(data, cache);
} }
async _fetchMany(cache) { async _fetchMany(cache) {
const data = await this.client.api.guilds(this.guild.id).bans.get(); const data = await this.client.api.guilds(this.guild.id).bans.get();
return data.reduce((col, ban) => col.set(ban.user.id, this.add(ban, cache)), new Collection()); return data.reduce((col, ban) => col.set(ban.user.id, this._add(ban, cache)), new Collection());
} }
/** /**

View File

@@ -42,7 +42,7 @@ class GuildChannelManager extends CachedManager {
* @name GuildChannelManager#cache * @name GuildChannelManager#cache
*/ */
add(channel) { _add(channel) {
const existing = this.cache.get(channel.id); const existing = this.cache.get(channel.id);
if (existing) return existing; if (existing) return existing;
this.cache.set(channel.id, channel); this.cache.set(channel.id, channel);
@@ -169,12 +169,12 @@ class GuildChannelManager extends CachedManager {
const data = await this.client.api.channels(id).get(); const data = await this.client.api.channels(id).get();
// Since this is the guild manager, throw if on a different guild // Since this is the guild manager, throw if on a different guild
if (this.guild.id !== data.guild_id) throw new Error('GUILD_CHANNEL_UNOWNED'); if (this.guild.id !== data.guild_id) throw new Error('GUILD_CHANNEL_UNOWNED');
return this.client.channels.add(data, this.guild, cache); return this.client.channels._add(data, this.guild, cache);
} }
const data = await this.client.api.guilds(this.guild.id).channels.get(); const data = await this.client.api.guilds(this.guild.id).channels.get();
const channels = new Collection(); const channels = new Collection();
for (const channel of data) channels.set(channel.id, this.client.channels.add(channel, this.guild, cache)); for (const channel of data) channels.set(channel.id, this.client.channels._add(channel, this.guild, cache));
return channels; return channels;
} }
} }

View File

@@ -20,8 +20,8 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
this.guild = guild; this.guild = guild;
} }
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { extras: [this.guild] }); return super._add(data, cache, { extras: [this.guild] });
} }
/** /**
@@ -94,12 +94,12 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
if (existing) return existing; if (existing) return existing;
} }
const emoji = await this.client.api.guilds(this.guild.id).emojis(id).get(); const emoji = await this.client.api.guilds(this.guild.id).emojis(id).get();
return this.add(emoji, cache); return this._add(emoji, cache);
} }
const data = await this.client.api.guilds(this.guild.id).emojis.get(); const data = await this.client.api.guilds(this.guild.id).emojis.get();
const emojis = new Collection(); const emojis = new Collection();
for (const emoji of data) emojis.set(emoji.id, this.add(emoji, cache)); for (const emoji of data) emojis.set(emoji.id, this._add(emoji, cache));
return emojis; return emojis;
} }
} }

View File

@@ -27,8 +27,8 @@ class GuildInviteManager extends CachedManager {
* @name GuildInviteManager#cache * @name GuildInviteManager#cache
*/ */
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { id: data.code, extras: [this.guild] }); return super._add(data, cache, { id: data.code, extras: [this.guild] });
} }
/** /**
@@ -142,12 +142,12 @@ class GuildInviteManager extends CachedManager {
async _fetchMany(cache) { async _fetchMany(cache) {
const data = await this.client.api.guilds(this.guild.id).invites.get(); const data = await this.client.api.guilds(this.guild.id).invites.get();
return data.reduce((col, invite) => col.set(invite.code, this.add(invite, cache)), new Collection()); return data.reduce((col, invite) => col.set(invite.code, this._add(invite, cache)), new Collection());
} }
async _fetchChannelMany(channelID, cache) { async _fetchChannelMany(channelID, cache) {
const data = await this.client.api.channels(channelID).invites.get(); const data = await this.client.api.channels(channelID).invites.get();
return data.reduce((col, invite) => col.set(invite.code, this.add(invite, cache)), new Collection()); return data.reduce((col, invite) => col.set(invite.code, this._add(invite, cache)), new Collection());
} }
/** /**

View File

@@ -229,7 +229,7 @@ class GuildManager extends CachedManager {
const timeout = this.client.setTimeout(() => { const timeout = this.client.setTimeout(() => {
this.client.removeListener(Events.GUILD_CREATE, handleGuild); this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.decrementMaxListeners(); this.client.decrementMaxListeners();
resolve(this.client.guilds.add(data)); resolve(this.client.guilds._add(data));
}, 10000); }, 10000);
return undefined; return undefined;
}, reject), }, reject),
@@ -265,7 +265,7 @@ class GuildManager extends CachedManager {
} }
const data = await this.client.api.guilds(id).get({ query: { with_counts: true } }); const data = await this.client.api.guilds(id).get({ query: { with_counts: true } });
return this.add(data, options.cache); return this._add(data, options.cache);
} }
const data = await this.client.api.users('@me').guilds.get({ query: options }); const data = await this.client.api.users('@me').guilds.get({ query: options });

View File

@@ -30,8 +30,8 @@ class GuildMemberManager extends CachedManager {
* @name GuildMemberManager#cache * @name GuildMemberManager#cache
*/ */
add(data, cache = true) { _add(data, cache = true) {
return super.add(data, cache, { id: data.user.id, extras: [this.guild] }); return super._add(data, cache, { id: data.user.id, extras: [this.guild] });
} }
/** /**
@@ -152,7 +152,7 @@ class GuildMemberManager extends CachedManager {
*/ */
async search({ query, limit = 1, cache = true } = {}) { async search({ query, limit = 1, cache = true } = {}) {
const data = await this.client.api.guilds(this.guild.id).members.search.get({ query: { query, limit } }); const data = await this.client.api.guilds(this.guild.id).members.search.get({ query: { query, limit } });
return data.reduce((col, member) => col.set(member.user.id, this.add(member, cache)), new Collection()); return data.reduce((col, member) => col.set(member.user.id, this._add(member, cache)), new Collection());
} }
/** /**
@@ -193,7 +193,7 @@ class GuildMemberManager extends CachedManager {
const clone = this.cache.get(id)?._clone(); const clone = this.cache.get(id)?._clone();
clone?._patch(d); clone?._patch(d);
return clone ?? this.add(d, false); return clone ?? this._add(d, false);
} }
/** /**
@@ -326,7 +326,7 @@ class GuildMemberManager extends CachedManager {
.guilds(this.guild.id) .guilds(this.guild.id)
.members(user) .members(user)
.get() .get()
.then(data => this.add(data, cache)); .then(data => this._add(data, cache));
} }
_fetchMany({ _fetchMany({

View File

@@ -27,8 +27,8 @@ class MessageManager extends CachedManager {
* @name MessageManager#cache * @name MessageManager#cache
*/ */
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { extras: [this.channel] }); return super._add(data, cache, { extras: [this.channel] });
} }
/** /**
@@ -83,7 +83,7 @@ class MessageManager extends CachedManager {
fetchPinned(cache = true) { fetchPinned(cache = true) {
return this.client.api.channels[this.channel.id].pins.get().then(data => { return this.client.api.channels[this.channel.id].pins.get().then(data => {
const messages = new Collection(); const messages = new Collection();
for (const message of data) messages.set(message.id, this.add(message, cache)); for (const message of data) messages.set(message.id, this._add(message, cache));
return messages; return messages;
}); });
} }
@@ -137,7 +137,7 @@ class MessageManager extends CachedManager {
clone._patch(d); clone._patch(d);
return clone; return clone;
} }
return this.add(d); return this._add(d);
} }
/** /**
@@ -150,7 +150,7 @@ class MessageManager extends CachedManager {
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
const data = await this.client.api.channels(this.channel.id).messages(message).crosspost.post(); const data = await this.client.api.channels(this.channel.id).messages(message).crosspost.post();
return this.cache.get(data.id) ?? this.add(data); return this.cache.get(data.id) ?? this._add(data);
} }
/** /**
@@ -213,13 +213,13 @@ class MessageManager extends CachedManager {
} }
const data = await this.client.api.channels[this.channel.id].messages[messageId].get(); const data = await this.client.api.channels[this.channel.id].messages[messageId].get();
return this.add(data, cache); return this._add(data, cache);
} }
async _fetchMany(options = {}, cache) { async _fetchMany(options = {}, cache) {
const data = await this.client.api.channels[this.channel.id].messages.get({ query: options }); const data = await this.client.api.channels[this.channel.id].messages.get({ query: options });
const messages = new Collection(); const messages = new Collection();
for (const message of data) messages.set(message.id, this.add(message, cache)); for (const message of data) messages.set(message.id, this._add(message, cache));
return messages; return messages;
} }
} }

View File

@@ -28,8 +28,8 @@ class PermissionOverwriteManager extends CachedManager {
* @name PermissionOverwriteManager#cache * @name PermissionOverwriteManager#cache
*/ */
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { extras: [this.channel] }); return super._add(data, cache, { extras: [this.channel] });
} }
/** /**

View File

@@ -18,8 +18,8 @@ class PresenceManager extends CachedManager {
* @name PresenceManager#cache * @name PresenceManager#cache
*/ */
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { id: data.user.id }); return super._add(data, cache, { id: data.user.id });
} }
/** /**

View File

@@ -18,8 +18,8 @@ class ReactionManager extends CachedManager {
this.message = message; this.message = message;
} }
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { id: data.emoji.id ?? data.emoji.name, extras: [this.message] }); return super._add(data, cache, { id: data.emoji.id ?? data.emoji.name, extras: [this.message] });
} }
/** /**

View File

@@ -45,7 +45,7 @@ class ReactionUserManager extends CachedManager {
].get({ query: { limit, after } }); ].get({ query: { limit, after } });
const users = new Collection(); const users = new Collection();
for (const rawUser of data) { for (const rawUser of data) {
const user = this.client.users.add(rawUser); const user = this.client.users._add(rawUser);
this.cache.set(user.id, user); this.cache.set(user.id, user);
users.set(user.id, user); users.set(user.id, user);
} }

View File

@@ -28,8 +28,8 @@ class RoleManager extends CachedManager {
* @name RoleManager#cache * @name RoleManager#cache
*/ */
add(data, cache) { _add(data, cache) {
return super.add(data, cache, { extras: [this.guild] }); return super._add(data, cache, { extras: [this.guild] });
} }
/** /**
@@ -57,7 +57,7 @@ class RoleManager extends CachedManager {
// We cannot fetch a single role, as of this commit's date, Discord API throws with 405 // We cannot fetch a single role, as of this commit's date, Discord API throws with 405
const data = await this.client.api.guilds(this.guild.id).roles.get(); const data = await this.client.api.guilds(this.guild.id).roles.get();
const roles = new Collection(); const roles = new Collection();
for (const role of data) roles.set(role.id, this.add(role, cache)); for (const role of data) roles.set(role.id, this._add(role, cache));
return id ? roles.get(id) ?? null : roles; return id ? roles.get(id) ?? null : roles;
} }

View File

@@ -63,7 +63,7 @@ class StageInstanceManager extends CachedManager {
}, },
}); });
return this.add(data); return this._add(data);
} }
/** /**
@@ -87,7 +87,7 @@ class StageInstanceManager extends CachedManager {
} }
const data = await this.client.api('stage-instances', channelId).get(); const data = await this.client.api('stage-instances', channelId).get();
return this.add(data, cache); return this._add(data, cache);
} }
/** /**
@@ -130,7 +130,7 @@ class StageInstanceManager extends CachedManager {
return clone; return clone;
} }
return this.add(data); return this._add(data);
} }
/** /**

View File

@@ -27,7 +27,7 @@ class ThreadManager extends CachedManager {
* @name ThreadManager#cache * @name ThreadManager#cache
*/ */
add(thread) { _add(thread) {
const existing = this.cache.get(thread.id); const existing = this.cache.get(thread.id);
if (existing) return existing; if (existing) return existing;
this.cache.set(thread.id, thread); this.cache.set(thread.id, thread);
@@ -234,7 +234,7 @@ class ThreadManager extends CachedManager {
_mapThreads(rawThreads, cache) { _mapThreads(rawThreads, cache) {
const threads = rawThreads.threads.reduce((coll, raw) => { const threads = rawThreads.threads.reduce((coll, raw) => {
const thread = this.client.channels.add(raw, null, cache); const thread = this.client.channels._add(raw, null, cache);
return coll.set(thread.id, thread); return coll.set(thread.id, thread);
}, new Collection()); }, new Collection());
// Discord sends the thread id as id in this object // Discord sends the thread id as id in this object

View File

@@ -67,7 +67,7 @@ class UserManager extends CachedManager {
} }
const data = await this.client.api.users(id).get(); const data = await this.client.api.users(id).get();
return this.add(data, cache); return this._add(data, cache);
} }
} }

View File

@@ -24,7 +24,7 @@ class VoiceStateManager extends CachedManager {
* @name VoiceStateManager#cache * @name VoiceStateManager#cache
*/ */
add(data, cache = true) { _add(data, cache = true) {
const existing = this.cache.get(data.user_id); const existing = this.cache.get(data.user_id);
if (existing) return existing._patch(data); if (existing) return existing._patch(data);

View File

@@ -101,7 +101,7 @@ class BaseGuild extends Base {
*/ */
async fetch() { async fetch() {
const data = await this.client.api.guilds(this.id).get({ query: { with_counts: true } }); const data = await this.client.api.guilds(this.id).get({ query: { with_counts: true } });
return this.client.guilds.add(data); return this.client.guilds._add(data);
} }
/** /**

View File

@@ -60,7 +60,7 @@ class ClientApplication extends Application {
this.owner = data.team this.owner = data.team
? new Team(this.client, data.team) ? new Team(this.client, data.team)
: data.owner : data.owner
? this.client.users.add(data.owner) ? this.client.users._add(data.owner)
: this.owner ?? null; : this.owner ?? null;
} }

View File

@@ -112,16 +112,16 @@ class CommandInteraction extends Interaction {
if (resolved) { if (resolved) {
const user = resolved.users?.[option.value]; const user = resolved.users?.[option.value];
if (user) result.user = this.client.users.add(user); if (user) result.user = this.client.users._add(user);
const member = resolved.members?.[option.value]; const member = resolved.members?.[option.value];
if (member) result.member = this.guild?.members.add({ user, ...member }) ?? member; if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member;
const channel = resolved.channels?.[option.value]; const channel = resolved.channels?.[option.value];
if (channel) result.channel = this.client.channels.add(channel, this.guild) ?? channel; if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel;
const role = resolved.roles?.[option.value]; const role = resolved.roles?.[option.value];
if (role) result.role = this.guild?.roles.add(role) ?? role; if (role) result.role = this.guild?.roles._add(role) ?? role;
} }
return result; return result;

View File

@@ -34,7 +34,7 @@ class DMChannel extends Channel {
* The recipient on the other end of the DM * The recipient on the other end of the DM
* @type {User} * @type {User}
*/ */
this.recipient = this.client.users.add(data.recipients[0]); this.recipient = this.client.users._add(data.recipients[0]);
} }
/** /**

View File

@@ -343,24 +343,24 @@ class Guild extends AnonymousGuild {
if (data.channels) { if (data.channels) {
this.channels.cache.clear(); this.channels.cache.clear();
for (const rawChannel of data.channels) { for (const rawChannel of data.channels) {
this.client.channels.add(rawChannel, this); this.client.channels._add(rawChannel, this);
} }
} }
if (data.threads) { if (data.threads) {
for (const rawThread of data.threads) { for (const rawThread of data.threads) {
this.client.channels.add(rawThread, this); this.client.channels._add(rawThread, this);
} }
} }
if (data.roles) { if (data.roles) {
this.roles.cache.clear(); this.roles.cache.clear();
for (const role of data.roles) this.roles.add(role); for (const role of data.roles) this.roles._add(role);
} }
if (data.members) { if (data.members) {
this.members.cache.clear(); this.members.cache.clear();
for (const guildUser of data.members) this.members.add(guildUser); for (const guildUser of data.members) this.members._add(guildUser);
} }
if (data.owner_id) { if (data.owner_id) {
@@ -373,21 +373,21 @@ class Guild extends AnonymousGuild {
if (data.presences) { if (data.presences) {
for (const presence of data.presences) { for (const presence of data.presences) {
this.presences.add(Object.assign(presence, { guild: this })); this.presences._add(Object.assign(presence, { guild: this }));
} }
} }
if (data.stage_instances) { if (data.stage_instances) {
this.stageInstances.cache.clear(); this.stageInstances.cache.clear();
for (const stageInstance of data.stage_instances) { for (const stageInstance of data.stage_instances) {
this.stageInstances.add(stageInstance); this.stageInstances._add(stageInstance);
} }
} }
if (data.voice_states) { if (data.voice_states) {
this.voiceStates.cache.clear(); this.voiceStates.cache.clear();
for (const voiceState of data.voice_states) { for (const voiceState of data.voice_states) {
this.voiceStates.add(voiceState); this.voiceStates._add(voiceState);
} }
} }
@@ -397,7 +397,7 @@ class Guild extends AnonymousGuild {
* @type {GuildEmojiManager} * @type {GuildEmojiManager}
*/ */
this.emojis = new GuildEmojiManager(this); this.emojis = new GuildEmojiManager(this);
if (data.emojis) for (const emoji of data.emojis) this.emojis.add(emoji); if (data.emojis) for (const emoji of data.emojis) this.emojis._add(emoji);
} else if (data.emojis) { } else if (data.emojis) {
this.client.actions.GuildEmojisUpdate.handle({ this.client.actions.GuildEmojisUpdate.handle({
guild_id: this.id, guild_id: this.id,
@@ -513,7 +513,7 @@ class Guild extends AnonymousGuild {
return ( return (
this.members.resolve(this.client.user.id) ?? this.members.resolve(this.client.user.id) ??
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
? this.members.add({ user: { id: this.client.user.id } }, true) ? this.members._add({ user: { id: this.client.user.id } }, true)
: null) : null)
); );
} }
@@ -759,7 +759,7 @@ class Guild extends AnonymousGuild {
} }
const data = await this.client.api.guilds(this.id).members(user).put({ data: options }); const data = await this.client.api.guilds(this.id).members(user).put({ data: options });
// Data is an empty buffer if the member is already part of the guild. // Data is an empty buffer if the member is already part of the guild.
return data instanceof Buffer ? this.members.fetch(user) : this.members.add(data); return data instanceof Buffer ? this.members.fetch(user) : this.members._add(data);
} }
/** /**

View File

@@ -140,7 +140,7 @@ const Actions = {
*/ */
class GuildAuditLogs { class GuildAuditLogs {
constructor(guild, data) { constructor(guild, data) {
if (data.users) for (const user of data.users) guild.client.users.add(user); if (data.users) for (const user of data.users) guild.client.users._add(user);
/** /**
* Cached webhooks * Cached webhooks
* @type {Collection<Snowflake, Webhook>} * @type {Collection<Snowflake, Webhook>}
@@ -340,7 +340,7 @@ class GuildAuditLogsEntry {
*/ */
this.executor = data.user_id this.executor = data.user_id
? guild.client.options.partials.includes(PartialTypes.USER) ? guild.client.options.partials.includes(PartialTypes.USER)
? guild.client.users.add({ id: data.user_id }) ? guild.client.users._add({ id: data.user_id })
: guild.client.users.cache.get(data.user_id) : guild.client.users.cache.get(data.user_id)
: null; : null;
@@ -450,7 +450,7 @@ class GuildAuditLogsEntry {
// MEMBER_DISCONNECT and similar types do not provide a target_id. // MEMBER_DISCONNECT and similar types do not provide a target_id.
} else if (targetType === Targets.USER && data.target_id) { } else if (targetType === Targets.USER && data.target_id) {
this.target = guild.client.options.partials.includes(PartialTypes.USER) this.target = guild.client.options.partials.includes(PartialTypes.USER)
? guild.client.users.add({ id: data.target_id }) ? guild.client.users._add({ id: data.target_id })
: guild.client.users.cache.get(data.target_id); : guild.client.users.cache.get(data.target_id);
} else if (targetType === Targets.GUILD) { } else if (targetType === Targets.GUILD) {
this.target = guild.client.guilds.cache.get(data.target_id); this.target = guild.client.guilds.cache.get(data.target_id);

View File

@@ -29,7 +29,7 @@ class GuildBan extends Base {
* The user this ban applies to * The user this ban applies to
* @type {User} * @type {User}
*/ */
this.user = this.client.users.add(data.user, true); this.user = this.client.users._add(data.user, true);
if ('reason' in data) { if ('reason' in data) {
/** /**

View File

@@ -85,7 +85,7 @@ class GuildChannel extends Channel {
if ('permission_overwrites' in data) { if ('permission_overwrites' in data) {
this.permissionOverwrites.cache.clear(); this.permissionOverwrites.cache.clear();
for (const overwrite of data.permission_overwrites) { for (const overwrite of data.permission_overwrites) {
this.permissionOverwrites.add(overwrite); this.permissionOverwrites._add(overwrite);
} }
} }
} }

View File

@@ -48,7 +48,7 @@ class GuildEmoji extends BaseGuildEmoji {
_patch(data) { _patch(data) {
super._patch(data); super._patch(data);
if (data.user) this.author = this.client.users.add(data.user); if (data.user) this.author = this.client.users._add(data.user);
if (data.roles) this._roles = data.roles; if (data.roles) this._roles = data.roles;
} }

View File

@@ -67,7 +67,7 @@ class GuildMember extends Base {
* The user that this guild member instance represents * The user that this guild member instance represents
* @type {User} * @type {User}
*/ */
this.user = this.client.users.add(data.user, true); this.user = this.client.users._add(data.user, true);
} }
if ('nick' in data) this.nickname = data.nick; if ('nick' in data) this.nickname = data.nick;

View File

@@ -59,7 +59,7 @@ class GuildTemplate extends Base {
* The user that created this template * The user that created this template
* @type {User} * @type {User}
*/ */
this.creator = this.client.users.add(data.creator); this.creator = this.client.users._add(data.creator);
/** /**
* The time of when this template was created at * The time of when this template was created at
@@ -130,7 +130,7 @@ class GuildTemplate extends Base {
client.incrementMaxListeners(); client.incrementMaxListeners();
client.on(Events.GUILD_CREATE, handleGuild); client.on(Events.GUILD_CREATE, handleGuild);
const timeout = client.setTimeout(() => resolveGuild(client.guilds.add(data)), 10000); const timeout = client.setTimeout(() => resolveGuild(client.guilds._add(data)), 10000);
}); });
} }

View File

@@ -64,7 +64,7 @@ class Integration extends Base {
* The user for this integration * The user for this integration
* @type {?User} * @type {?User}
*/ */
this.user = this.client.users.add(data.user); this.user = this.client.users._add(data.user);
} else { } else {
this.user = null; this.user = null;
} }

View File

@@ -14,7 +14,7 @@ class IntegrationApplication extends Application {
* The bot user for this application * The bot user for this application
* @type {?User} * @type {?User}
*/ */
this.bot = data.bot ? this.client.users.add(data.bot) : this.bot ?? null; this.bot = data.bot ? this.client.users._add(data.bot) : this.bot ?? null;
/** /**
* The url of the application's terms of service * The url of the application's terms of service

View File

@@ -54,13 +54,13 @@ class Interaction extends Base {
* The user which sent this interaction * The user which sent this interaction
* @type {User} * @type {User}
*/ */
this.user = this.client.users.add(data.user ?? data.member.user); this.user = this.client.users._add(data.user ?? data.member.user);
/** /**
* If this interaction was sent in a guild, the member which sent it * If this interaction was sent in a guild, the member which sent it
* @type {?(GuildMember|APIGuildMember)} * @type {?(GuildMember|APIGuildMember)}
*/ */
this.member = data.member ? this.guild?.members.add(data.member) ?? data.member : null; this.member = data.member ? this.guild?.members._add(data.member) ?? data.member : null;
/** /**
* The version * The version

View File

@@ -76,13 +76,13 @@ class Invite extends Base {
* The user who created this invite * The user who created this invite
* @type {?User} * @type {?User}
*/ */
this.inviter = data.inviter ? this.client.users.add(data.inviter) : null; this.inviter = data.inviter ? this.client.users._add(data.inviter) : null;
/** /**
* The user whose stream to display for this voice channel stream invite * The user whose stream to display for this voice channel stream invite
* @type {?User} * @type {?User}
*/ */
this.targetUser = data.target_user ? this.client.users.add(data.target_user) : null; this.targetUser = data.target_user ? this.client.users._add(data.target_user) : null;
/** /**
* The embedded application to open for this voice channel embedded application invite * The embedded application to open for this voice channel embedded application invite
@@ -109,7 +109,7 @@ class Invite extends Base {
* The channel the invite is for * The channel the invite is for
* @type {Channel} * @type {Channel}
*/ */
this.channel = this.client.channels.add(data.channel, this.guild, false); this.channel = this.client.channels._add(data.channel, this.guild, false);
/** /**
* The timestamp the invite was created at * The timestamp the invite was created at

View File

@@ -53,7 +53,7 @@ class InviteStageInstance extends Base {
this.members.clear(); this.members.clear();
for (const rawMember of data.members) { for (const rawMember of data.members) {
const member = this.guild.members.add(rawMember); const member = this.guild.members._add(rawMember);
this.members.set(member.id, member); this.members.set(member.id, member);
} }
} }

View File

@@ -86,7 +86,7 @@ class Message extends Base {
* The author of the message * The author of the message
* @type {?User} * @type {?User}
*/ */
this.author = this.client.users.add(data.author, !data.webhook_id); this.author = this.client.users._add(data.author, !data.webhook_id);
} else if (!this.author) { } else if (!this.author) {
this.author = null; this.author = null;
} }
@@ -106,7 +106,7 @@ class Message extends Base {
* The thread started by this message * The thread started by this message
* @type {?ThreadChannel} * @type {?ThreadChannel}
*/ */
this.thread = this.client.channels.add(data.thread); this.thread = this.client.channels._add(data.thread);
} else if (!this.thread) { } else if (!this.thread) {
this.thread = null; this.thread = null;
} }
@@ -182,7 +182,7 @@ class Message extends Base {
this.reactions = new ReactionManager(this); this.reactions = new ReactionManager(this);
if (data.reactions?.length > 0) { if (data.reactions?.length > 0) {
for (const reaction of data.reactions) { for (const reaction of data.reactions) {
this.reactions.add(reaction); this.reactions._add(reaction);
} }
} }
@@ -231,7 +231,7 @@ class Message extends Base {
if (this.member && data.member) { if (this.member && data.member) {
this.member._patch(data.member); this.member._patch(data.member);
} else if (data.member && this.guild && this.author) { } else if (data.member && this.guild && this.author) {
this.guild.members.add(Object.assign(data.member, { user: this.author })); this.guild.members._add(Object.assign(data.member, { user: this.author }));
} }
/** /**
@@ -261,7 +261,7 @@ class Message extends Base {
: null; : null;
if (data.referenced_message) { if (data.referenced_message) {
this.channel.messages.add(data.referenced_message); this.channel.messages._add(data.referenced_message);
} }
/** /**
@@ -282,7 +282,7 @@ class Message extends Base {
id: data.interaction.id, id: data.interaction.id,
type: InteractionTypes[data.interaction.type], type: InteractionTypes[data.interaction.type],
commandName: data.interaction.name, commandName: data.interaction.name,
user: this.client.users.add(data.interaction.user), user: this.client.users._add(data.interaction.user),
}; };
} else if (!this.interaction) { } else if (!this.interaction) {
this.interaction = null; this.interaction = null;
@@ -311,7 +311,7 @@ class Message extends Base {
if ('content' in data) this.content = data.content; if ('content' in data) this.content = data.content;
if ('pinned' in data) this.pinned = data.pinned; if ('pinned' in data) this.pinned = data.pinned;
if ('tts' in data) this.tts = data.tts; if ('tts' in data) this.tts = data.tts;
if ('thread' in data) this.thread = this.client.channels.add(data.thread); if ('thread' in data) this.thread = this.client.channels._add(data.thread);
if ('attachments' in data) { if ('attachments' in data) {
this.attachments = new Collection(); this.attachments = new Collection();

View File

@@ -18,7 +18,7 @@ class MessageComponentInteraction extends Interaction {
* The message to which the component was attached * The message to which the component was attached
* @type {Message|APIMessage} * @type {Message|APIMessage}
*/ */
this.message = this.channel?.messages.add(data.message) ?? data.message; this.message = this.channel?.messages._add(data.message) ?? data.message;
/** /**
* The custom id of the component which was interacted with * The custom id of the component which was interacted with

View File

@@ -49,9 +49,9 @@ class MessageMentions {
this.users = new Collection(); this.users = new Collection();
for (const mention of users) { for (const mention of users) {
if (mention.member && message.guild) { if (mention.member && message.guild) {
message.guild.members.add(Object.assign(mention.member, { user: mention })); message.guild.members._add(Object.assign(mention.member, { user: mention }));
} }
const user = message.client.users.add(mention); const user = message.client.users._add(mention);
this.users.set(user.id, user); this.users.set(user.id, user);
} }
} }
@@ -130,7 +130,7 @@ class MessageMentions {
* The author of the message that this message is a reply to * The author of the message that this message is a reply to
* @type {?User} * @type {?User}
*/ */
this.repliedUser = repliedUser ? this.client.users.add(repliedUser) : null; this.repliedUser = repliedUser ? this.client.users._add(repliedUser) : null;
} }
/** /**

View File

@@ -37,7 +37,7 @@ class TeamMember extends Base {
* The user for this Team Member * The user for this Team Member
* @type {User} * @type {User}
*/ */
this.user = this.client.users.add(data.user); this.user = this.client.users._add(data.user);
} }
/** /**

View File

@@ -90,7 +90,7 @@ class TextChannel extends GuildChannel {
} }
if ('messages' in data) { if ('messages' in data) {
for (const message of data.messages) this.messages.add(message); for (const message of data.messages) this.messages._add(message);
} }
} }

View File

@@ -150,7 +150,7 @@ class ThreadChannel extends Channel {
} }
if (data.member && this.client.user) this.members._add({ user_id: this.client.user.id, ...data.member }); if (data.member && this.client.user) this.members._add({ user_id: this.client.user.id, ...data.member });
if (data.messages) for (const message of data.messages) this.messages.add(message); if (data.messages) for (const message of data.messages) this.messages._add(message);
} }
/** /**

View File

@@ -212,7 +212,7 @@ class User extends Base {
recipient_id: this.id, recipient_id: this.id,
}, },
}); });
return this.client.channels.add(data); return this.client.channels._add(data);
} }
/** /**
@@ -223,7 +223,7 @@ class User extends Base {
const { dmChannel } = this; const { dmChannel } = this;
if (!dmChannel) throw new Error('USER_NO_DMCHANNEL'); if (!dmChannel) throw new Error('USER_NO_DMCHANNEL');
await this.client.api.channels(dmChannel.id).delete(); await this.client.api.channels(dmChannel.id).delete();
this.client.channels.remove(dmChannel.id); this.client.channels._remove(dmChannel.id);
return dmChannel; return dmChannel;
} }

View File

@@ -70,14 +70,14 @@ class Webhook {
* The owner of the webhook * The owner of the webhook
* @type {?(User|APIUser)} * @type {?(User|APIUser)}
*/ */
this.owner = data.user ? this.client.users?.add(data.user) ?? data.user : null; this.owner = data.user ? this.client.users?._add(data.user) ?? data.user : null;
/** /**
* The source guild of the webhook * The source guild of the webhook
* @type {?(Guild|APIGuild)} * @type {?(Guild|APIGuild)}
*/ */
this.sourceGuild = data.source_guild this.sourceGuild = data.source_guild
? this.client.guilds?.add(data.source_guild, false) ?? data.source_guild ? this.client.guilds?._add(data.source_guild, false) ?? data.source_guild
: null; : null;
/** /**
@@ -175,7 +175,7 @@ class Webhook {
query: { thread_id: messagePayload.options.threadId, wait: true }, query: { thread_id: messagePayload.options.threadId, wait: true },
auth: false, auth: false,
}) })
.then(d => this.client.channels?.cache.get(d.channel_id)?.messages.add(d, false) ?? d); .then(d => this.client.channels?.cache.get(d.channel_id)?.messages._add(d, false) ?? d);
} }
/** /**
@@ -250,7 +250,7 @@ class Webhook {
if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE'); if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE');
const data = await this.client.api.webhooks(this.id, this.token).messages(message).get(); const data = await this.client.api.webhooks(this.id, this.token).messages(message).get();
return this.client.channels?.cache.get(data.channel_id)?.messages.add(data, cache) ?? data; return this.client.channels?.cache.get(data.channel_id)?.messages._add(data, cache) ?? data;
} }
/** /**
@@ -279,7 +279,7 @@ class Webhook {
if (!messageManager) return d; if (!messageManager) return d;
const existing = messageManager.cache.get(d.id); const existing = messageManager.cache.get(d.id);
if (!existing) return messageManager.add(d); if (!existing) return messageManager._add(d);
const clone = existing._clone(); const clone = existing._clone();
clone._patch(d); clone._patch(d);

View File

@@ -7,7 +7,8 @@ const { Client, Options, Intents, Formatters } = require('../src');
const log = (...args) => console.log(process.uptime().toFixed(3), ...args); const log = (...args) => console.log(process.uptime().toFixed(3), ...args);
const client = new Client({ const client = new Client({
intents: Intents.ALL, // 😏
intents: Object.values(Intents.FLAGS).reduce((acc, p) => acc | p, 0),
makeCache: Options.cacheWithLimits({ makeCache: Options.cacheWithLimits({
MessageManager: 10, MessageManager: 10,
PresenceManager: 10, PresenceManager: 10,

7
typings/index.d.ts vendored
View File

@@ -2054,7 +2054,7 @@ export abstract class DataManager<K, Holds, R> extends BaseManager {
export abstract class CachedManager<K, Holds, R> extends DataManager<K, Holds, R> { export abstract class CachedManager<K, Holds, R> extends DataManager<K, Holds, R> {
public constructor(client: Client, holds: Constructable<Holds>); public constructor(client: Client, holds: Constructable<Holds>);
public add(data: unknown, cache?: boolean, { id, extras }?: { id: K; extras: unknown[] }): Holds; private _add(data: unknown, cache?: boolean, { id, extras }?: { id: K; extras: unknown[] }): Holds;
} }
export class ApplicationCommandManager< export class ApplicationCommandManager<
@@ -2373,12 +2373,9 @@ export class ThreadManager<AllowedThreadType> extends CachedManager<Snowflake, T
public fetchActive(cache?: boolean): Promise<FetchedThreads>; public fetchActive(cache?: boolean): Promise<FetchedThreads>;
} }
export interface ThreadMemberManager export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable> {
extends Omit<CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable>, 'add'> {}
export class ThreadMemberManager {
public constructor(thread: ThreadChannel, iterable?: Iterable<unknown>); public constructor(thread: ThreadChannel, iterable?: Iterable<unknown>);
public thread: ThreadChannel; public thread: ThreadChannel;
public _add(data: unknown, cache?: boolean): ThreadMember;
public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>; public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>;
public fetch(cache?: boolean): Promise<Collection<Snowflake, ThreadMember>>; public fetch(cache?: boolean): Promise<Collection<Snowflake, ThreadMember>>;
public remove(id: Snowflake | '@me', reason?: string): Promise<Snowflake>; public remove(id: Snowflake | '@me', reason?: string): Promise<Snowflake>;