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

@@ -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);
}
/**

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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());
}
/**

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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());
}
/**

View File

@@ -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 });

View File

@@ -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({

View File

@@ -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;
}
}

View File

@@ -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] });
}
/**

View File

@@ -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 });
}
/**

View File

@@ -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] });
}
/**

View File

@@ -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);
}

View File

@@ -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;
}

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();
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);
}
/**

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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);