mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(Managers): rename add to _add (#6060)
This commit is contained in:
@@ -26,7 +26,7 @@ class GenericAction {
|
||||
getPayload(data, manager, id, partialType, cache) {
|
||||
const existing = manager.cache.get(id);
|
||||
if (!existing && this.client.options.partials.includes(partialType)) {
|
||||
return manager.add(data, cache);
|
||||
return manager._add(data, cache);
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
@@ -93,9 +93,9 @@ class GenericAction {
|
||||
if (data.guild_id && data.member?.user) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
return guild.members.add(data.member).user;
|
||||
return guild.members._add(data.member).user;
|
||||
} else {
|
||||
return this.client.users.add(data.member.user);
|
||||
return this.client.users._add(data.member.user);
|
||||
}
|
||||
}
|
||||
return this.getUser(data);
|
||||
|
||||
@@ -7,7 +7,7 @@ class ChannelCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const existing = client.channels.cache.has(data.id);
|
||||
const channel = client.channels.add(data);
|
||||
const channel = client.channels._add(data);
|
||||
if (!existing && channel) {
|
||||
/**
|
||||
* Emitted whenever a guild channel is created.
|
||||
|
||||
@@ -15,7 +15,7 @@ class ChannelDeleteAction extends Action {
|
||||
const channel = client.channels.cache.get(data.id);
|
||||
|
||||
if (channel) {
|
||||
client.channels.remove(channel.id);
|
||||
client.channels._remove(channel.id);
|
||||
channel.deleted = true;
|
||||
if (channel.messages && !(channel instanceof DMChannel)) {
|
||||
for (const message of channel.messages.cache.values()) {
|
||||
|
||||
@@ -25,7 +25,7 @@ class ChannelUpdateAction extends Action {
|
||||
updated: channel,
|
||||
};
|
||||
} else {
|
||||
client.channels.add(data);
|
||||
client.channels._add(data);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
||||
@@ -13,7 +13,7 @@ class GuildBanAdd extends Action {
|
||||
* @event Client#guildBanAdd
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
// Delete guild
|
||||
|
||||
@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
|
||||
class GuildEmojiCreateAction extends Action {
|
||||
handle(guild, createdEmoji) {
|
||||
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.
|
||||
* @event Client#emojiCreate
|
||||
|
||||
@@ -9,7 +9,7 @@ class GuildMemberUpdateAction extends Action {
|
||||
if (data.user.username) {
|
||||
const user = client.users.cache.get(data.user.id);
|
||||
if (!user) {
|
||||
client.users.add(data.user);
|
||||
client.users._add(data.user);
|
||||
} else if (!user.equals(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);
|
||||
} else {
|
||||
const newMember = guild.members.add(data);
|
||||
const newMember = guild.members._add(data);
|
||||
/**
|
||||
* Emitted whenever a member becomes available in a large guild.
|
||||
* @event Client#guildMemberAvailable
|
||||
|
||||
@@ -10,7 +10,7 @@ class GuildRoleCreate extends Action {
|
||||
let role;
|
||||
if (guild) {
|
||||
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.
|
||||
* @event Client#roleCreate
|
||||
|
||||
@@ -11,7 +11,7 @@ class InviteCreateAction extends Action {
|
||||
if (!channel) return false;
|
||||
|
||||
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.
|
||||
|
||||
@@ -12,7 +12,7 @@ class MessageCreateAction extends Action {
|
||||
if (channel) {
|
||||
const existing = channel.messages.cache.get(data.id);
|
||||
if (existing) return { message: existing };
|
||||
const message = channel.messages.add(data);
|
||||
const message = channel.messages._add(data);
|
||||
channel.lastMessageId = data.id;
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ class MessageReactionAdd extends Action {
|
||||
if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false;
|
||||
const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name);
|
||||
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,
|
||||
count: message.partial ? null : 0,
|
||||
me: user.id === this.client.user.id,
|
||||
|
||||
@@ -6,7 +6,7 @@ const { Events } = require('../../util/Constants');
|
||||
class PresenceUpdateAction extends Action {
|
||||
handle(data) {
|
||||
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 (data.user?.username) {
|
||||
@@ -19,14 +19,14 @@ class PresenceUpdateAction extends Action {
|
||||
const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
|
||||
let member = guild.members.cache.get(user.id);
|
||||
if (!member && data.status !== 'offline') {
|
||||
member = guild.members.add({
|
||||
member = guild.members._add({
|
||||
user,
|
||||
deaf: false,
|
||||
mute: false,
|
||||
});
|
||||
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)) {
|
||||
/**
|
||||
* Emitted whenever a guild member's presence (e.g. status, activity) is changed.
|
||||
|
||||
@@ -9,7 +9,7 @@ class StageInstanceCreateAction extends Action {
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const stageInstance = channel.guild.stageInstances.add(data);
|
||||
const stageInstance = channel.guild.stageInstances._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a stage instance is created.
|
||||
|
||||
@@ -9,7 +9,7 @@ class StageInstanceDeleteAction extends Action {
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const stageInstance = channel.guild.stageInstances.add(data);
|
||||
const stageInstance = channel.guild.stageInstances._add(data);
|
||||
if (stageInstance) {
|
||||
channel.guild.stageInstances.cache.delete(stageInstance.id);
|
||||
stageInstance.deleted = true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class StageInstanceUpdateAction extends Action {
|
||||
|
||||
if (channel) {
|
||||
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
|
||||
|
||||
@@ -7,7 +7,7 @@ class ThreadCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const existing = client.channels.cache.has(data.id);
|
||||
const thread = client.channels.add(data);
|
||||
const thread = client.channels._add(data);
|
||||
if (!existing && thread) {
|
||||
/**
|
||||
* Emitted whenever a thread is created or when the client user is added to a thread.
|
||||
|
||||
@@ -9,7 +9,7 @@ class ThreadDeleteAction extends Action {
|
||||
const thread = client.channels.cache.get(data.id);
|
||||
|
||||
if (thread) {
|
||||
client.channels.remove(thread.id);
|
||||
client.channels._remove(thread.id);
|
||||
thread.deleted = true;
|
||||
for (const message of thread.messages.cache.values()) {
|
||||
message.deleted = true;
|
||||
|
||||
@@ -23,7 +23,7 @@ class ThreadListSyncAction extends Action {
|
||||
}
|
||||
|
||||
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);
|
||||
}, new Collection());
|
||||
|
||||
@@ -50,7 +50,7 @@ class ThreadListSyncAction extends Action {
|
||||
removeStale(channel) {
|
||||
channel.threads?.cache.forEach(thread => {
|
||||
if (!thread.archived) {
|
||||
this.client.channels.remove(thread.id);
|
||||
this.client.channels._remove(thread.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ class VoiceStateUpdate extends Action {
|
||||
const oldState =
|
||||
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
|
||||
let member = guild.members.cache.get(data.user_id);
|
||||
if (member && data.member) {
|
||||
member._patch(data.member);
|
||||
} else if (data.member?.user && data.member.joined_at) {
|
||||
member = guild.members.add(data.member);
|
||||
member = guild.members._add(data.member);
|
||||
}
|
||||
|
||||
// Emit event
|
||||
|
||||
@@ -8,9 +8,9 @@ module.exports = (client, { d: data }) => {
|
||||
if (data.guild_id) {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
command = guild.commands.add(data);
|
||||
command = guild.commands._add(data);
|
||||
} else {
|
||||
command = client.application.commands.add(data);
|
||||
command = client.application.commands._add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,10 +8,10 @@ module.exports = (client, { d: data }) => {
|
||||
if (data.guild_id) {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
command = guild.commands.add(data);
|
||||
command = guild.commands._add(data);
|
||||
guild.commands.cache.delete(data.id);
|
||||
} else {
|
||||
command = client.application.commands.add(data);
|
||||
command = client.application.commands._add(data);
|
||||
client.application.commands.cache.delete(data.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ module.exports = (client, { d: data }) => {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
oldCommand = guild.commands.cache.get(data.id)?._clone() ?? null;
|
||||
newCommand = guild.commands.add(data);
|
||||
newCommand = guild.commands._add(data);
|
||||
} else {
|
||||
oldCommand = client.application.commands.cache.get(data.id)?._clone() ?? null;
|
||||
newCommand = client.application.commands.add(data);
|
||||
newCommand = client.application.commands._add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ module.exports = (client, { d: data }, shard) => {
|
||||
} else {
|
||||
// A new guild
|
||||
data.shardId = shard.id;
|
||||
guild = client.guilds.add(data);
|
||||
guild = client.guilds._add(data);
|
||||
if (client.ws.status === Status.READY) {
|
||||
/**
|
||||
* Emitted whenever the client joins a guild.
|
||||
|
||||
@@ -8,9 +8,9 @@ module.exports = (client, { d: data }) => {
|
||||
if (!guild) return;
|
||||
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) {
|
||||
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).
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = (client, { d: data }, shard) => {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
guild.memberCount++;
|
||||
const member = guild.members.add(data);
|
||||
const member = guild.members._add(data);
|
||||
if (shard.status === Status.READY) {
|
||||
/**
|
||||
* Emitted whenever a user joins a guild.
|
||||
|
||||
@@ -14,7 +14,7 @@ module.exports = (client, { d: data }, shard) => {
|
||||
|
||||
for (const guild of data.guilds) {
|
||||
guild.shardId = shard.id;
|
||||
client.guilds.add(guild);
|
||||
client.guilds._add(guild);
|
||||
}
|
||||
|
||||
if (client.application) {
|
||||
|
||||
@@ -27,8 +27,8 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* @name ApplicationCommandManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache, guildId) {
|
||||
return super.add(data, cache, { extras: [this.guild, guildId] });
|
||||
_add(data, cache, guildId) {
|
||||
return super._add(data, cache, { extras: [this.guild, guildId] });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,11 +90,11 @@ class ApplicationCommandManager extends CachedManager {
|
||||
if (existing) return existing;
|
||||
}
|
||||
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();
|
||||
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({
|
||||
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)),
|
||||
});
|
||||
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(),
|
||||
);
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ class CachedManager extends DataManager {
|
||||
|
||||
if (iterable) {
|
||||
for (const item of iterable) {
|
||||
this.add(item);
|
||||
this._add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class CachedManager extends DataManager {
|
||||
return this._cache;
|
||||
}
|
||||
|
||||
add(data, cache = true, { id, extras = [] } = {}) {
|
||||
_add(data, cache = true, { id, extras = [] } = {}) {
|
||||
const existing = this.cache.get(id ?? data.id);
|
||||
if (cache) existing?._patch(data);
|
||||
if (existing) return existing;
|
||||
|
||||
@@ -19,13 +19,13 @@ class ChannelManager extends CachedManager {
|
||||
* @name ChannelManager#cache
|
||||
*/
|
||||
|
||||
add(data, guild, cache = true, allowUnknownGuild = false) {
|
||||
_add(data, guild, cache = true, allowUnknownGuild = false) {
|
||||
const existing = this.cache.get(data.id);
|
||||
if (existing) {
|
||||
if (cache) existing._patch(data);
|
||||
guild?.channels?.add(existing);
|
||||
guild?.channels?._add(existing);
|
||||
if (ThreadChannelTypes.includes(existing.type)) {
|
||||
existing.parent?.threads?.add(existing);
|
||||
existing.parent?.threads?._add(existing);
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class ChannelManager extends CachedManager {
|
||||
return channel;
|
||||
}
|
||||
|
||||
remove(id) {
|
||||
_remove(id) {
|
||||
const channel = this.cache.get(id);
|
||||
channel?.guild?.channels.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();
|
||||
return this.add(data, null, cache, allowUnknownGuild);
|
||||
return this._add(data, null, cache, allowUnknownGuild);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ class GuildBanManager extends CachedManager {
|
||||
* @name GuildBanManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { id: data.user.id, extras: [this.guild] });
|
||||
_add(data, cache) {
|
||||
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();
|
||||
return this.add(data, cache);
|
||||
return this._add(data, cache);
|
||||
}
|
||||
|
||||
async _fetchMany(cache) {
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,7 +42,7 @@ class GuildChannelManager extends CachedManager {
|
||||
* @name GuildChannelManager#cache
|
||||
*/
|
||||
|
||||
add(channel) {
|
||||
_add(channel) {
|
||||
const existing = this.cache.get(channel.id);
|
||||
if (existing) return existing;
|
||||
this.cache.set(channel.id, channel);
|
||||
@@ -169,12 +169,12 @@ class GuildChannelManager extends CachedManager {
|
||||
const data = await this.client.api.channels(id).get();
|
||||
// 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');
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { extras: [this.guild] });
|
||||
_add(data, cache) {
|
||||
return super._add(data, cache, { extras: [this.guild] });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,12 +94,12 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
|
||||
if (existing) return existing;
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ class GuildInviteManager extends CachedManager {
|
||||
* @name GuildInviteManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { id: data.code, extras: [this.guild] });
|
||||
_add(data, cache) {
|
||||
return super._add(data, cache, { id: data.code, extras: [this.guild] });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,12 +142,12 @@ class GuildInviteManager extends CachedManager {
|
||||
|
||||
async _fetchMany(cache) {
|
||||
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) {
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -229,7 +229,7 @@ class GuildManager extends CachedManager {
|
||||
const timeout = this.client.setTimeout(() => {
|
||||
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
|
||||
this.client.decrementMaxListeners();
|
||||
resolve(this.client.guilds.add(data));
|
||||
resolve(this.client.guilds._add(data));
|
||||
}, 10000);
|
||||
return undefined;
|
||||
}, reject),
|
||||
@@ -265,7 +265,7 @@ class GuildManager extends CachedManager {
|
||||
}
|
||||
|
||||
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 });
|
||||
|
||||
@@ -30,8 +30,8 @@ class GuildMemberManager extends CachedManager {
|
||||
* @name GuildMemberManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache = true) {
|
||||
return super.add(data, cache, { id: data.user.id, extras: [this.guild] });
|
||||
_add(data, cache = true) {
|
||||
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 } = {}) {
|
||||
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();
|
||||
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)
|
||||
.members(user)
|
||||
.get()
|
||||
.then(data => this.add(data, cache));
|
||||
.then(data => this._add(data, cache));
|
||||
}
|
||||
|
||||
_fetchMany({
|
||||
|
||||
@@ -27,8 +27,8 @@ class MessageManager extends CachedManager {
|
||||
* @name MessageManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { extras: [this.channel] });
|
||||
_add(data, cache) {
|
||||
return super._add(data, cache, { extras: [this.channel] });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ class MessageManager extends CachedManager {
|
||||
fetchPinned(cache = true) {
|
||||
return this.client.api.channels[this.channel.id].pins.get().then(data => {
|
||||
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;
|
||||
});
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class MessageManager extends CachedManager {
|
||||
clone._patch(d);
|
||||
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');
|
||||
|
||||
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();
|
||||
return this.add(data, cache);
|
||||
return this._add(data, cache);
|
||||
}
|
||||
|
||||
async _fetchMany(options = {}, cache) {
|
||||
const data = await this.client.api.channels[this.channel.id].messages.get({ query: options });
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ class PermissionOverwriteManager extends CachedManager {
|
||||
* @name PermissionOverwriteManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { extras: [this.channel] });
|
||||
_add(data, cache) {
|
||||
return super._add(data, cache, { extras: [this.channel] });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,8 +18,8 @@ class PresenceManager extends CachedManager {
|
||||
* @name PresenceManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { id: data.user.id });
|
||||
_add(data, cache) {
|
||||
return super._add(data, cache, { id: data.user.id });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,8 +18,8 @@ class ReactionManager extends CachedManager {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { id: data.emoji.id ?? data.emoji.name, extras: [this.message] });
|
||||
_add(data, cache) {
|
||||
return super._add(data, cache, { id: data.emoji.id ?? data.emoji.name, extras: [this.message] });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ class ReactionUserManager extends CachedManager {
|
||||
].get({ query: { limit, after } });
|
||||
const users = new Collection();
|
||||
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);
|
||||
users.set(user.id, user);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ class RoleManager extends CachedManager {
|
||||
* @name RoleManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { extras: [this.guild] });
|
||||
_add(data, cache) {
|
||||
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
|
||||
const data = await this.client.api.guilds(this.guild.id).roles.get();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
return this.add(data, cache);
|
||||
return this._add(data, cache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +130,7 @@ class StageInstanceManager extends CachedManager {
|
||||
return clone;
|
||||
}
|
||||
|
||||
return this.add(data);
|
||||
return this._add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ class ThreadManager extends CachedManager {
|
||||
* @name ThreadManager#cache
|
||||
*/
|
||||
|
||||
add(thread) {
|
||||
_add(thread) {
|
||||
const existing = this.cache.get(thread.id);
|
||||
if (existing) return existing;
|
||||
this.cache.set(thread.id, thread);
|
||||
@@ -234,7 +234,7 @@ class ThreadManager extends CachedManager {
|
||||
|
||||
_mapThreads(rawThreads, cache) {
|
||||
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);
|
||||
}, new Collection());
|
||||
// Discord sends the thread id as id in this object
|
||||
|
||||
@@ -67,7 +67,7 @@ class UserManager extends CachedManager {
|
||||
}
|
||||
|
||||
const data = await this.client.api.users(id).get();
|
||||
return this.add(data, cache);
|
||||
return this._add(data, cache);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class VoiceStateManager extends CachedManager {
|
||||
* @name VoiceStateManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache = true) {
|
||||
_add(data, cache = true) {
|
||||
const existing = this.cache.get(data.user_id);
|
||||
if (existing) return existing._patch(data);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ class BaseGuild extends Base {
|
||||
*/
|
||||
async fetch() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,7 +60,7 @@ class ClientApplication extends Application {
|
||||
this.owner = data.team
|
||||
? new Team(this.client, data.team)
|
||||
: data.owner
|
||||
? this.client.users.add(data.owner)
|
||||
? this.client.users._add(data.owner)
|
||||
: this.owner ?? null;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,16 +112,16 @@ class CommandInteraction extends Interaction {
|
||||
|
||||
if (resolved) {
|
||||
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];
|
||||
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];
|
||||
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];
|
||||
if (role) result.role = this.guild?.roles.add(role) ?? role;
|
||||
if (role) result.role = this.guild?.roles._add(role) ?? role;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -34,7 +34,7 @@ class DMChannel extends Channel {
|
||||
* The recipient on the other end of the DM
|
||||
* @type {User}
|
||||
*/
|
||||
this.recipient = this.client.users.add(data.recipients[0]);
|
||||
this.recipient = this.client.users._add(data.recipients[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -343,24 +343,24 @@ class Guild extends AnonymousGuild {
|
||||
if (data.channels) {
|
||||
this.channels.cache.clear();
|
||||
for (const rawChannel of data.channels) {
|
||||
this.client.channels.add(rawChannel, this);
|
||||
this.client.channels._add(rawChannel, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.threads) {
|
||||
for (const rawThread of data.threads) {
|
||||
this.client.channels.add(rawThread, this);
|
||||
this.client.channels._add(rawThread, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.roles) {
|
||||
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) {
|
||||
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) {
|
||||
@@ -373,21 +373,21 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
if (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) {
|
||||
this.stageInstances.cache.clear();
|
||||
for (const stageInstance of data.stage_instances) {
|
||||
this.stageInstances.add(stageInstance);
|
||||
this.stageInstances._add(stageInstance);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
this.voiceStates.cache.clear();
|
||||
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}
|
||||
*/
|
||||
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) {
|
||||
this.client.actions.GuildEmojisUpdate.handle({
|
||||
guild_id: this.id,
|
||||
@@ -513,7 +513,7 @@ class Guild extends AnonymousGuild {
|
||||
return (
|
||||
this.members.resolve(this.client.user.id) ??
|
||||
(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)
|
||||
);
|
||||
}
|
||||
@@ -759,7 +759,7 @@ class Guild extends AnonymousGuild {
|
||||
}
|
||||
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.
|
||||
return data instanceof Buffer ? this.members.fetch(user) : this.members.add(data);
|
||||
return data instanceof Buffer ? this.members.fetch(user) : this.members._add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -140,7 +140,7 @@ const Actions = {
|
||||
*/
|
||||
class GuildAuditLogs {
|
||||
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
|
||||
* @type {Collection<Snowflake, Webhook>}
|
||||
@@ -340,7 +340,7 @@ class GuildAuditLogsEntry {
|
||||
*/
|
||||
this.executor = data.user_id
|
||||
? 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)
|
||||
: null;
|
||||
|
||||
@@ -450,7 +450,7 @@ class GuildAuditLogsEntry {
|
||||
// MEMBER_DISCONNECT and similar types do not provide a target_id.
|
||||
} else if (targetType === Targets.USER && data.target_id) {
|
||||
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);
|
||||
} else if (targetType === Targets.GUILD) {
|
||||
this.target = guild.client.guilds.cache.get(data.target_id);
|
||||
|
||||
@@ -29,7 +29,7 @@ class GuildBan extends Base {
|
||||
* The user this ban applies to
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user, true);
|
||||
this.user = this.client.users._add(data.user, true);
|
||||
|
||||
if ('reason' in data) {
|
||||
/**
|
||||
|
||||
@@ -85,7 +85,7 @@ class GuildChannel extends Channel {
|
||||
if ('permission_overwrites' in data) {
|
||||
this.permissionOverwrites.cache.clear();
|
||||
for (const overwrite of data.permission_overwrites) {
|
||||
this.permissionOverwrites.add(overwrite);
|
||||
this.permissionOverwrites._add(overwrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class GuildEmoji extends BaseGuildEmoji {
|
||||
_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;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class GuildMember extends Base {
|
||||
* The user that this guild member instance represents
|
||||
* @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;
|
||||
|
||||
@@ -59,7 +59,7 @@ class GuildTemplate extends Base {
|
||||
* The user that created this template
|
||||
* @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
|
||||
@@ -130,7 +130,7 @@ class GuildTemplate extends Base {
|
||||
client.incrementMaxListeners();
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class Integration extends Base {
|
||||
* The user for this integration
|
||||
* @type {?User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user);
|
||||
this.user = this.client.users._add(data.user);
|
||||
} else {
|
||||
this.user = null;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class IntegrationApplication extends Application {
|
||||
* The bot user for this application
|
||||
* @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
|
||||
|
||||
@@ -54,13 +54,13 @@ class Interaction extends Base {
|
||||
* The user which sent this interaction
|
||||
* @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
|
||||
* @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
|
||||
|
||||
@@ -76,13 +76,13 @@ class Invite extends Base {
|
||||
* The user who created this invite
|
||||
* @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
|
||||
* @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
|
||||
@@ -109,7 +109,7 @@ class Invite extends Base {
|
||||
* The channel the invite is for
|
||||
* @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
|
||||
|
||||
@@ -53,7 +53,7 @@ class InviteStageInstance extends Base {
|
||||
|
||||
this.members.clear();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class Message extends Base {
|
||||
* The author of the message
|
||||
* @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) {
|
||||
this.author = null;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ class Message extends Base {
|
||||
* The thread started by this message
|
||||
* @type {?ThreadChannel}
|
||||
*/
|
||||
this.thread = this.client.channels.add(data.thread);
|
||||
this.thread = this.client.channels._add(data.thread);
|
||||
} else if (!this.thread) {
|
||||
this.thread = null;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ class Message extends Base {
|
||||
this.reactions = new ReactionManager(this);
|
||||
if (data.reactions?.length > 0) {
|
||||
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) {
|
||||
this.member._patch(data.member);
|
||||
} 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;
|
||||
|
||||
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,
|
||||
type: InteractionTypes[data.interaction.type],
|
||||
commandName: data.interaction.name,
|
||||
user: this.client.users.add(data.interaction.user),
|
||||
user: this.client.users._add(data.interaction.user),
|
||||
};
|
||||
} else if (!this.interaction) {
|
||||
this.interaction = null;
|
||||
@@ -311,7 +311,7 @@ class Message extends Base {
|
||||
if ('content' in data) this.content = data.content;
|
||||
if ('pinned' in data) this.pinned = data.pinned;
|
||||
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) {
|
||||
this.attachments = new Collection();
|
||||
|
||||
@@ -18,7 +18,7 @@ class MessageComponentInteraction extends Interaction {
|
||||
* The message to which the component was attached
|
||||
* @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
|
||||
|
||||
@@ -49,9 +49,9 @@ class MessageMentions {
|
||||
this.users = new Collection();
|
||||
for (const mention of users) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class MessageMentions {
|
||||
* The author of the message that this message is a reply to
|
||||
* @type {?User}
|
||||
*/
|
||||
this.repliedUser = repliedUser ? this.client.users.add(repliedUser) : null;
|
||||
this.repliedUser = repliedUser ? this.client.users._add(repliedUser) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ class TeamMember extends Base {
|
||||
* The user for this Team Member
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user);
|
||||
this.user = this.client.users._add(data.user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ class TextChannel extends GuildChannel {
|
||||
}
|
||||
|
||||
if ('messages' in data) {
|
||||
for (const message of data.messages) this.messages.add(message);
|
||||
for (const message of data.messages) this.messages._add(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.messages) for (const message of data.messages) this.messages.add(message);
|
||||
if (data.messages) for (const message of data.messages) this.messages._add(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -212,7 +212,7 @@ class User extends Base {
|
||||
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;
|
||||
if (!dmChannel) throw new Error('USER_NO_DMCHANNEL');
|
||||
await this.client.api.channels(dmChannel.id).delete();
|
||||
this.client.channels.remove(dmChannel.id);
|
||||
this.client.channels._remove(dmChannel.id);
|
||||
return dmChannel;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,14 +70,14 @@ class Webhook {
|
||||
* The owner of the webhook
|
||||
* @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
|
||||
* @type {?(Guild|APIGuild)}
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ class Webhook {
|
||||
query: { thread_id: messagePayload.options.threadId, wait: true },
|
||||
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');
|
||||
|
||||
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;
|
||||
|
||||
const existing = messageManager.cache.get(d.id);
|
||||
if (!existing) return messageManager.add(d);
|
||||
if (!existing) return messageManager._add(d);
|
||||
|
||||
const clone = existing._clone();
|
||||
clone._patch(d);
|
||||
|
||||
@@ -7,7 +7,8 @@ const { Client, Options, Intents, Formatters } = require('../src');
|
||||
const log = (...args) => console.log(process.uptime().toFixed(3), ...args);
|
||||
|
||||
const client = new Client({
|
||||
intents: Intents.ALL,
|
||||
// 😏
|
||||
intents: Object.values(Intents.FLAGS).reduce((acc, p) => acc | p, 0),
|
||||
makeCache: Options.cacheWithLimits({
|
||||
MessageManager: 10,
|
||||
PresenceManager: 10,
|
||||
|
||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -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> {
|
||||
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<
|
||||
@@ -2373,12 +2373,9 @@ export class ThreadManager<AllowedThreadType> extends CachedManager<Snowflake, T
|
||||
public fetchActive(cache?: boolean): Promise<FetchedThreads>;
|
||||
}
|
||||
|
||||
export interface ThreadMemberManager
|
||||
extends Omit<CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable>, 'add'> {}
|
||||
export class ThreadMemberManager {
|
||||
export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable> {
|
||||
public constructor(thread: ThreadChannel, iterable?: Iterable<unknown>);
|
||||
public thread: ThreadChannel;
|
||||
public _add(data: unknown, cache?: boolean): ThreadMember;
|
||||
public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>;
|
||||
public fetch(cache?: boolean): Promise<Collection<Snowflake, ThreadMember>>;
|
||||
public remove(id: Snowflake | '@me', reason?: string): Promise<Snowflake>;
|
||||
|
||||
Reference in New Issue
Block a user