mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +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) {
|
||||
|
||||
Reference in New Issue
Block a user