mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
feat: remove datastores and implement Managers (#3696)
* Initial commit: add 5 initial managers - Base manager - GuildChannelManager - MessageManager - PresenceManager - Reaction Manager - Added LimitedCollection * Add GuildEmojiManager, various fixes * Modify some managers and add guildmembermanager * Initial integration * Delete old stores * Integration part two, removed LRUCollection - Most of the integration has been finished - TODO typings - Removed LRUCollection, needless sweeping * Typings + stuff i somehow missed in ChannelManager * LimitedCollection typings/ final changes * Various jsdoc and syntactical fixes, Removed Util.mixin() * tslint fix * Grammatical and logical changes * Delete temporary file placed by mistake * Grammatical changes * Add missing type * Update jsdoc examples * fix: ChannelManager#remove should call cache#delete not cache#remove * fix recursive require * Fix missed cache in util * fix: more missed cache * Remove accidental _fetchMany change from #3645 * fix: use .cache.delete() over .remove() * fix: missing cache in ReactionCollector * fix: missed cache in client * fix: members is a collection not a manager Co-Authored-By: Sugden <28943913+NotSugden@users.noreply.github.com> * fix: various docs and cache fixes * fix: missed cache * fix: missing _roles * Final testing and debugging * LimitedCollection: return the Collection instead of undefined on .set * Add cache to BaseManager in typings * Commit fixes i forgot to stage yesterday * Update invite events * Account for new commit * fix: MessageReactionRemoveAll should call .cache.clear() * fix: add .cache at various places, correct return type * docs: remove mentions of 'store' * Add extra documented properties to typings Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
@@ -13,7 +13,7 @@ class CategoryChannel extends GuildChannel {
|
||||
* @readonly
|
||||
*/
|
||||
get children() {
|
||||
return this.guild.channels.filter(c => c.parentID === this.id);
|
||||
return this.guild.channels.cache.filter(c => c.parentID === this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,7 +100,7 @@ class Channel extends Base {
|
||||
const DMChannel = Structures.get('DMChannel');
|
||||
channel = new DMChannel(client, data);
|
||||
} else {
|
||||
guild = guild || client.guilds.get(data.guild_id);
|
||||
guild = guild || client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
switch (data.type) {
|
||||
case ChannelTypes.TEXT: {
|
||||
@@ -129,7 +129,7 @@ class Channel extends Base {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (channel) guild.channels.set(channel.id, channel);
|
||||
if (channel) guild.channels.cache.set(channel.id, channel);
|
||||
}
|
||||
}
|
||||
return channel;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const Channel = require('./Channel');
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const MessageStore = require('../stores/MessageStore');
|
||||
const MessageManager = require('../managers/MessageManager');
|
||||
|
||||
/**
|
||||
* Represents a direct message channel between two users.
|
||||
@@ -19,10 +19,10 @@ class DMChannel extends Channel {
|
||||
// Override the channel type so partials have a known type
|
||||
this.type = 'dm';
|
||||
/**
|
||||
* A collection containing the messages sent to this channel
|
||||
* @type {MessageStore<Snowflake, Message>}
|
||||
* A manager of the messages belonging to this channel
|
||||
* @type {MessageManager}
|
||||
*/
|
||||
this.messages = new MessageStore(this);
|
||||
this.messages = new MessageManager(this);
|
||||
this._typing = new Map();
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class Emoji extends Base {
|
||||
* @returns {string}
|
||||
* @example
|
||||
* // Send a custom emoji from a guild:
|
||||
* const emoji = guild.emojis.first();
|
||||
* const emoji = guild.emojis.cache.first();
|
||||
* msg.reply(`Hello! ${emoji}`);
|
||||
* @example
|
||||
* // Send the emoji used in a reaction to the channel the reaction is part of
|
||||
|
||||
@@ -11,12 +11,12 @@ const Util = require('../util/Util');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
||||
const GuildMemberStore = require('../stores/GuildMemberStore');
|
||||
const RoleStore = require('../stores/RoleStore');
|
||||
const GuildEmojiStore = require('../stores/GuildEmojiStore');
|
||||
const GuildChannelStore = require('../stores/GuildChannelStore');
|
||||
const PresenceStore = require('../stores/PresenceStore');
|
||||
const VoiceStateStore = require('../stores/VoiceStateStore');
|
||||
const GuildMemberManager = require('../managers/GuildMemberManager');
|
||||
const RoleManager = require('../managers/RoleManager');
|
||||
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
||||
const GuildChannelManager = require('../managers/GuildChannelManager');
|
||||
const PresenceManager = require('../managers/PresenceManager');
|
||||
const VoiceStateManager = require('../managers/VoiceStateManager');
|
||||
const Base = require('./Base');
|
||||
const { Error, TypeError } = require('../errors');
|
||||
|
||||
@@ -35,34 +35,34 @@ class Guild extends Base {
|
||||
super(client);
|
||||
|
||||
/**
|
||||
* A collection of members that are in this guild. The key is the member's ID, the value is the member
|
||||
* @type {GuildMemberStore<Snowflake, GuildMember>}
|
||||
* A manager of the members belonging to this guild
|
||||
* @type {GuildMemberManager}
|
||||
*/
|
||||
this.members = new GuildMemberStore(this);
|
||||
this.members = new GuildMemberManager(this);
|
||||
|
||||
/**
|
||||
* A collection of channels that are in this guild. The key is the channel's ID, the value is the channel
|
||||
* @type {GuildChannelStore<Snowflake, GuildChannel>}
|
||||
* A manager of the members belonging to this guild
|
||||
* @type {GuildChannelManager}
|
||||
*/
|
||||
this.channels = new GuildChannelStore(this);
|
||||
this.channels = new GuildChannelManager(this);
|
||||
|
||||
/**
|
||||
* A collection of roles that are in this guild. The key is the role's ID, the value is the role
|
||||
* @type {RoleStore<Snowflake, Role>}
|
||||
* A manager of the roles belonging to this guild
|
||||
* @type {RoleManager}
|
||||
*/
|
||||
this.roles = new RoleStore(this);
|
||||
this.roles = new RoleManager(this);
|
||||
|
||||
/**
|
||||
* A collection of presences in this guild
|
||||
* @type {PresenceStore<Snowflake, Presence>}
|
||||
* A manager of the presences belonging to this guild
|
||||
* @type {PresenceManager}
|
||||
*/
|
||||
this.presences = new PresenceStore(this.client);
|
||||
this.presences = new PresenceManager(this.client);
|
||||
|
||||
/**
|
||||
* A collection of voice states in this guild
|
||||
* @type {VoiceStateStore<Snowflake, VoiceState>}
|
||||
* A manager of the voice states of this guild
|
||||
* @type {VoiceStateManager}
|
||||
*/
|
||||
this.voiceStates = new VoiceStateStore(this);
|
||||
this.voiceStates = new VoiceStateManager(this);
|
||||
|
||||
/**
|
||||
* Whether the bot has been removed from the guild
|
||||
@@ -321,19 +321,19 @@ class Guild extends Base {
|
||||
this.features = data.features || this.features || [];
|
||||
|
||||
if (data.channels) {
|
||||
this.channels.clear();
|
||||
this.channels.cache.clear();
|
||||
for (const rawChannel of data.channels) {
|
||||
this.client.channels.add(rawChannel, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.roles) {
|
||||
this.roles.clear();
|
||||
this.roles.cache.clear();
|
||||
for (const role of data.roles) this.roles.add(role);
|
||||
}
|
||||
|
||||
if (data.members) {
|
||||
this.members.clear();
|
||||
this.members.cache.clear();
|
||||
for (const guildUser of data.members) this.members.add(guildUser);
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ class Guild extends Base {
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
this.voiceStates.clear();
|
||||
this.voiceStates.cache.clear();
|
||||
for (const voiceState of data.voice_states) {
|
||||
this.voiceStates.add(voiceState);
|
||||
}
|
||||
@@ -360,10 +360,10 @@ class Guild extends Base {
|
||||
|
||||
if (!this.emojis) {
|
||||
/**
|
||||
* A collection of emojis that are in this guild. The key is the emoji's ID, the value is the emoji.
|
||||
* @type {GuildEmojiStore<Snowflake, GuildEmoji>}
|
||||
* A manager of the emojis belonging to this guild
|
||||
* @type {GuildEmojiManager}
|
||||
*/
|
||||
this.emojis = new GuildEmojiStore(this);
|
||||
this.emojis = new GuildEmojiManager(this);
|
||||
if (data.emojis) for (const emoji of data.emojis) this.emojis.add(emoji);
|
||||
} else if (data.emojis) {
|
||||
this.client.actions.GuildEmojisUpdate.handle({
|
||||
@@ -463,7 +463,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get owner() {
|
||||
return this.members.get(this.ownerID) || (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
return this.members.cache.get(this.ownerID) || (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.ownerID } }, true) :
|
||||
null);
|
||||
}
|
||||
@@ -474,7 +474,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get afkChannel() {
|
||||
return this.client.channels.get(this.afkChannelID) || null;
|
||||
return this.client.channels.cache.get(this.afkChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -483,7 +483,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get systemChannel() {
|
||||
return this.client.channels.get(this.systemChannelID) || null;
|
||||
return this.client.channels.cache.get(this.systemChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -492,7 +492,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get widgetChannel() {
|
||||
return this.client.channels.get(this.widgetChannelID) || null;
|
||||
return this.client.channels.cache.get(this.widgetChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -501,7 +501,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get embedChannel() {
|
||||
return this.client.channels.get(this.embedChannelID) || null;
|
||||
return this.client.channels.cache.get(this.embedChannelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -510,9 +510,10 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get me() {
|
||||
return this.members.get(this.client.user.id) || (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.client.user.id } }, true) :
|
||||
null);
|
||||
return this.members.cache.get(this.client.user.id) ||
|
||||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.client.user.id } }, true) :
|
||||
null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -521,7 +522,7 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get voice() {
|
||||
return this.voiceStates.get(this.client.user.id);
|
||||
return this.voiceStates.cache.get(this.client.user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -716,7 +717,7 @@ class Guild extends Base {
|
||||
fetchEmbed() {
|
||||
return this.client.api.guilds(this.id).embed.get().then(data => ({
|
||||
enabled: data.enabled,
|
||||
channel: data.channel_id ? this.channels.get(data.channel_id) : null,
|
||||
channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -763,7 +764,7 @@ class Guild extends Base {
|
||||
addMember(user, options) {
|
||||
user = this.client.users.resolveID(user);
|
||||
if (!user) return Promise.reject(new TypeError('INVALID_TYPE', 'user', 'UserResolvable'));
|
||||
if (this.members.has(user)) return Promise.resolve(this.members.get(user));
|
||||
if (this.members.cache.has(user)) return Promise.resolve(this.members.cache.get(user));
|
||||
options.access_token = options.accessToken;
|
||||
if (options.roles) {
|
||||
const roles = [];
|
||||
@@ -988,7 +989,7 @@ class Guild extends Base {
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Edit the guild owner
|
||||
* guild.setOwner(guild.members.first())
|
||||
* guild.setOwner(guild.members.cache.first())
|
||||
* .then(updated => console.log(`Updated the guild owner to ${updated.owner.displayName}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
@@ -1203,7 +1204,7 @@ class Guild extends Base {
|
||||
* @private
|
||||
*/
|
||||
_sortedRoles() {
|
||||
return Util.discordSort(this.roles);
|
||||
return Util.discordSort(this.roles.cache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1214,7 +1215,7 @@ class Guild extends Base {
|
||||
*/
|
||||
_sortedChannels(channel) {
|
||||
const category = channel.type === ChannelTypes.CATEGORY;
|
||||
return Util.discordSort(this.channels.filter(c =>
|
||||
return Util.discordSort(this.channels.cache.filter(c =>
|
||||
c.type === channel.type && (category || c.parent === channel.parent)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ class GuildAuditLogsEntry {
|
||||
*/
|
||||
this.executor = guild.client.options.partials.includes(PartialTypes.USER) ?
|
||||
guild.client.users.add({ id: data.user_id }) :
|
||||
guild.client.users.get(data.user_id);
|
||||
guild.client.users.cache.get(data.user_id);
|
||||
|
||||
/**
|
||||
* An entry in the audit log representing a specific change.
|
||||
@@ -321,7 +321,7 @@ class GuildAuditLogsEntry {
|
||||
} else if (data.action_type === Actions.MESSAGE_DELETE) {
|
||||
this.extra = {
|
||||
count: data.options.count,
|
||||
channel: guild.channels.get(data.options.channel_id),
|
||||
channel: guild.channels.cache.get(data.options.channel_id),
|
||||
};
|
||||
} else if (data.action_type === Actions.MESSAGE_BULK_DELETE) {
|
||||
this.extra = {
|
||||
@@ -330,11 +330,11 @@ class GuildAuditLogsEntry {
|
||||
} else {
|
||||
switch (data.options.type) {
|
||||
case 'member':
|
||||
this.extra = guild.members.get(data.options.id);
|
||||
this.extra = guild.members.cache.get(data.options.id);
|
||||
if (!this.extra) this.extra = { id: data.options.id };
|
||||
break;
|
||||
case 'role':
|
||||
this.extra = guild.roles.get(data.options.id);
|
||||
this.extra = guild.roles.cache.get(data.options.id);
|
||||
if (!this.extra) this.extra = { id: data.options.id, name: data.options.role_name };
|
||||
break;
|
||||
default:
|
||||
@@ -357,9 +357,9 @@ class GuildAuditLogsEntry {
|
||||
} else if (targetType === Targets.USER) {
|
||||
this.target = guild.client.options.partials.includes(PartialTypes.USER) ?
|
||||
guild.client.users.add({ id: data.target_id }) :
|
||||
guild.client.users.get(data.target_id);
|
||||
guild.client.users.cache.get(data.target_id);
|
||||
} else if (targetType === Targets.GUILD) {
|
||||
this.target = guild.client.guilds.get(data.target_id);
|
||||
this.target = guild.client.guilds.cache.get(data.target_id);
|
||||
} else if (targetType === Targets.WEBHOOK) {
|
||||
this.target = logs.webhooks.get(data.target_id) ||
|
||||
new Webhook(guild.client,
|
||||
@@ -386,9 +386,9 @@ class GuildAuditLogsEntry {
|
||||
}
|
||||
});
|
||||
} else if (targetType === Targets.MESSAGE) {
|
||||
this.target = guild.client.users.get(data.target_id);
|
||||
this.target = guild.client.users.cache.get(data.target_id);
|
||||
} else {
|
||||
this.target = guild[`${targetType.toLowerCase()}s`].get(data.target_id) || { id: data.target_id };
|
||||
this.target = guild[`${targetType.toLowerCase()}s`].cache.get(data.target_id) || { id: data.target_id };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class GuildChannel extends Channel {
|
||||
* @readonly
|
||||
*/
|
||||
get parent() {
|
||||
return this.guild.channels.get(this.parentID) || null;
|
||||
return this.guild.channels.cache.get(this.parentID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +118,7 @@ class GuildChannel extends Channel {
|
||||
if (!verified) member = this.guild.members.resolve(member);
|
||||
if (!member) return [];
|
||||
|
||||
roles = roles || member.roles;
|
||||
roles = roles || member.roles.cache;
|
||||
const roleOverwrites = [];
|
||||
let memberOverwrites;
|
||||
let everyoneOverwrites;
|
||||
@@ -149,7 +149,7 @@ class GuildChannel extends Channel {
|
||||
memberPermissions(member) {
|
||||
if (member.id === this.guild.ownerID) return new Permissions(Permissions.ALL).freeze();
|
||||
|
||||
const roles = member.roles;
|
||||
const roles = member.roles.cache;
|
||||
const permissions = new Permissions(roles.map(role => role.permissions));
|
||||
|
||||
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return new Permissions(Permissions.ALL).freeze();
|
||||
@@ -274,7 +274,7 @@ class GuildChannel extends Channel {
|
||||
*/
|
||||
get members() {
|
||||
const members = new Collection();
|
||||
for (const member of this.guild.members.values()) {
|
||||
for (const member of this.guild.members.cache.values()) {
|
||||
if (this.permissionsFor(member).has('VIEW_CHANNEL', false)) {
|
||||
members.set(member.id, member);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const GuildEmojiRoleStore = require('../stores/GuildEmojiRoleStore');
|
||||
const GuildEmojiRoleManager = require('../managers/GuildEmojiRoleManager');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const { Error } = require('../errors');
|
||||
const Emoji = require('./Emoji');
|
||||
@@ -79,12 +79,12 @@ class GuildEmoji extends Emoji {
|
||||
}
|
||||
|
||||
/**
|
||||
* A collection of roles this emoji is active for (empty if all), mapped by role ID
|
||||
* @type {GuildEmojiRoleStore<Snowflake, Role>}
|
||||
* A manager for roles this emoji is active for.
|
||||
* @type {GuildEmojiRoleManager}
|
||||
* @readonly
|
||||
*/
|
||||
get roles() {
|
||||
return new GuildEmojiRoleStore(this);
|
||||
return new GuildEmojiRoleManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,15 +168,15 @@ class GuildEmoji extends Emoji {
|
||||
other.name === this.name &&
|
||||
other.managed === this.managed &&
|
||||
other.requiresColons === this.requiresColons &&
|
||||
other.roles.size === this.roles.size &&
|
||||
other.roles.every(role => this.roles.has(role.id))
|
||||
other.roles.cache.size === this.roles.cache.size &&
|
||||
other.roles.cache.every(role => this.roles.cache.has(role.id))
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
other.id === this.id &&
|
||||
other.name === this.name &&
|
||||
other.roles.length === this.roles.size &&
|
||||
other.roles.every(role => this.roles.has(role))
|
||||
other.roles.length === this.roles.cache.size &&
|
||||
other.roles.every(role => this.roles.cache.has(role))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const Role = require('./Role');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const GuildMemberRoleStore = require('../stores/GuildMemberRoleStore');
|
||||
const GuildMemberRoleManager = require('../managers/GuildMemberRoleManager');
|
||||
const Base = require('./Base');
|
||||
const VoiceState = require('./VoiceState');
|
||||
const { Presence } = require('./Presence');
|
||||
@@ -101,12 +101,12 @@ class GuildMember extends Base {
|
||||
}
|
||||
|
||||
/**
|
||||
* A collection of roles that are applied to this member, mapped by the role ID
|
||||
* @type {GuildMemberRoleStore<Snowflake, Role>}
|
||||
* A manager for the roles belonging to this member
|
||||
* @type {GuildMemberRoleManager}
|
||||
* @readonly
|
||||
*/
|
||||
get roles() {
|
||||
return new GuildMemberRoleStore(this);
|
||||
return new GuildMemberRoleManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,8 +115,8 @@ class GuildMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get lastMessage() {
|
||||
const channel = this.guild.channels.get(this.lastMessageChannelID);
|
||||
return (channel && channel.messages.get(this.lastMessageID)) || null;
|
||||
const channel = this.guild.channels.cache.get(this.lastMessageChannelID);
|
||||
return (channel && channel.messages.cache.get(this.lastMessageID)) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +125,7 @@ class GuildMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get voice() {
|
||||
return this.guild.voiceStates.get(this.id) || new VoiceState(this.guild, { user_id: this.id });
|
||||
return this.guild.voiceStates.cache.get(this.id) || new VoiceState(this.guild, { user_id: this.id });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +152,7 @@ class GuildMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get presence() {
|
||||
return this.guild.presences.get(this.id) || new Presence(this.client, {
|
||||
return this.guild.presences.cache.get(this.id) || new Presence(this.client, {
|
||||
user: {
|
||||
id: this.id,
|
||||
},
|
||||
@@ -205,7 +205,7 @@ class GuildMember extends Base {
|
||||
*/
|
||||
get permissions() {
|
||||
if (this.user.id === this.guild.ownerID) return new Permissions(Permissions.ALL).freeze();
|
||||
return new Permissions(this.roles.map(role => role.permissions)).freeze();
|
||||
return new Permissions(this.roles.cache.map(role => role.permissions)).freeze();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +261,7 @@ class GuildMember extends Base {
|
||||
*/
|
||||
hasPermission(permission, { checkAdmin = true, checkOwner = true } = {}) {
|
||||
if (checkOwner && this.user.id === this.guild.ownerID) return true;
|
||||
return this.roles.some(r => r.permissions.has(permission, checkAdmin));
|
||||
return this.roles.cache.some(r => r.permissions.has(permission, checkAdmin));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,7 +56,7 @@ class Integration extends Base {
|
||||
* The role that this integration uses for subscribers
|
||||
* @type {Role}
|
||||
*/
|
||||
this.role = this.guild.roles.get(data.role_id);
|
||||
this.role = this.guild.roles.cache.get(data.role_id);
|
||||
|
||||
/**
|
||||
* The user for this integration
|
||||
|
||||
@@ -117,7 +117,7 @@ class Invite extends Base {
|
||||
*/
|
||||
get deletable() {
|
||||
const guild = this.guild;
|
||||
if (!guild || !this.client.guilds.has(guild.id)) return false;
|
||||
if (!guild || !this.client.guilds.cache.has(guild.id)) return false;
|
||||
if (!guild.me) throw new Error('GUILD_UNCACHED_ME');
|
||||
return this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) ||
|
||||
guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD);
|
||||
|
||||
@@ -7,7 +7,7 @@ const ReactionCollector = require('./ReactionCollector');
|
||||
const ClientApplication = require('./ClientApplication');
|
||||
const Util = require('../util/Util');
|
||||
const Collection = require('../util/Collection');
|
||||
const ReactionStore = require('../stores/ReactionStore');
|
||||
const ReactionManager = require('../managers/ReactionManager');
|
||||
const { MessageTypes } = require('../util/Constants');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Base = require('./Base');
|
||||
@@ -126,10 +126,10 @@ class Message extends Base {
|
||||
this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp).getTime() : null;
|
||||
|
||||
/**
|
||||
* A collection of reactions to this message, mapped by the reaction ID
|
||||
* @type {ReactionStore<Snowflake, MessageReaction>}
|
||||
* A manager of the reactions belonging to this message
|
||||
* @type {ReactionManager}
|
||||
*/
|
||||
this.reactions = new ReactionStore(this);
|
||||
this.reactions = new ReactionManager(this);
|
||||
if (data.reactions && data.reactions.length > 0) {
|
||||
for (const reaction of data.reactions) {
|
||||
this.reactions.add(reaction);
|
||||
@@ -452,7 +452,7 @@ class Message extends Base {
|
||||
* .catch(console.error);
|
||||
* @example
|
||||
* // React to a message with a custom emoji
|
||||
* message.react(message.guild.emojis.get('123456789012345678'))
|
||||
* message.react(message.guild.emojis.cache.get('123456789012345678'))
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
@@ -484,7 +484,7 @@ class Message extends Base {
|
||||
*/
|
||||
delete({ timeout = 0, reason } = {}) {
|
||||
if (timeout <= 0) {
|
||||
return this.channel.messages.remove(this.id, reason).then(() => this);
|
||||
return this.channel.messages.delete(this.id, reason).then(() => this);
|
||||
} else {
|
||||
return new Promise(resolve => {
|
||||
this.client.setTimeout(() => {
|
||||
|
||||
@@ -71,7 +71,7 @@ class MessageMentions {
|
||||
} else {
|
||||
this.roles = new Collection();
|
||||
for (const mention of roles) {
|
||||
const role = message.channel.guild.roles.get(mention);
|
||||
const role = message.channel.guild.roles.cache.get(mention);
|
||||
if (role) this.roles.set(role.id, role);
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ class MessageMentions {
|
||||
this._channels = new Collection();
|
||||
let matches;
|
||||
while ((matches = this.constructor.CHANNELS_PATTERN.exec(this._content)) !== null) {
|
||||
const chan = this.client.channels.get(matches[1]);
|
||||
const chan = this.client.channels.cache.get(matches[1]);
|
||||
if (chan) this._channels.set(chan.id, chan);
|
||||
}
|
||||
return this._channels;
|
||||
@@ -175,7 +175,7 @@ class MessageMentions {
|
||||
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreEveryone = false } = {}) {
|
||||
if (!ignoreEveryone && this.everyone) return true;
|
||||
if (!ignoreRoles && data instanceof GuildMember) {
|
||||
for (const role of this.roles.values()) if (data.roles.has(role.id)) return true;
|
||||
for (const role of this.roles.values()) if (data.roles.cache.has(role.id)) return true;
|
||||
}
|
||||
|
||||
if (!ignoreDirect) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const GuildEmoji = require('./GuildEmoji');
|
||||
const Util = require('../util/Util');
|
||||
const ReactionEmoji = require('./ReactionEmoji');
|
||||
const ReactionUserStore = require('../stores/ReactionUserStore');
|
||||
const ReactionUserManager = require('../managers/ReactionUserManager');
|
||||
|
||||
/**
|
||||
* Represents a reaction to a message.
|
||||
@@ -35,10 +35,10 @@ class MessageReaction {
|
||||
this.me = data.me;
|
||||
|
||||
/**
|
||||
* The users that have given this reaction, mapped by their ID
|
||||
* @type {ReactionUserStore<Snowflake, User>}
|
||||
* A manager of the users that have given this reaction
|
||||
* @type {ReactionUserManager}
|
||||
*/
|
||||
this.users = new ReactionUserStore(client, undefined, this);
|
||||
this.users = new ReactionUserManager(client, undefined, this);
|
||||
|
||||
this._emoji = new ReactionEmoji(this, data.emoji);
|
||||
|
||||
@@ -75,7 +75,7 @@ class MessageReaction {
|
||||
if (this._emoji instanceof GuildEmoji) return this._emoji;
|
||||
// Check to see if the emoji has become known to the client
|
||||
if (this._emoji.id) {
|
||||
const emojis = this.message.client.emojis;
|
||||
const emojis = this.message.client.emojis.cache;
|
||||
if (emojis.has(this._emoji.id)) {
|
||||
const emoji = emojis.get(this._emoji.id);
|
||||
this._emoji = emoji;
|
||||
@@ -108,18 +108,18 @@ class MessageReaction {
|
||||
|
||||
_add(user) {
|
||||
if (this.partial) return;
|
||||
this.users.set(user.id, user);
|
||||
this.users.cache.set(user.id, user);
|
||||
if (!this.me || user.id !== this.message.client.user.id || this.count === 0) this.count++;
|
||||
if (!this.me) this.me = user.id === this.message.client.user.id;
|
||||
}
|
||||
|
||||
_remove(user) {
|
||||
if (this.partial) return;
|
||||
this.users.delete(user.id);
|
||||
this.users.cache.delete(user.id);
|
||||
if (!this.me || user.id !== this.message.client.user.id) this.count--;
|
||||
if (user.id === this.message.client.user.id) this.me = false;
|
||||
if (this.count <= 0 && this.users.size === 0) {
|
||||
this.message.reactions.remove(this.emoji.id || this.emoji.name);
|
||||
if (this.count <= 0 && this.users.cache.size === 0) {
|
||||
this.message.reactions.cache.delete(this.emoji.id || this.emoji.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class Presence {
|
||||
* @readonly
|
||||
*/
|
||||
get user() {
|
||||
return this.client.users.get(this.userID) || null;
|
||||
return this.client.users.cache.get(this.userID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +75,7 @@ class Presence {
|
||||
* @readonly
|
||||
*/
|
||||
get member() {
|
||||
return this.guild.members.get(this.userID) || null;
|
||||
return this.guild.members.cache.get(this.userID) || null;
|
||||
}
|
||||
|
||||
patch(data) {
|
||||
|
||||
@@ -74,7 +74,7 @@ class ReactionCollector extends Collector {
|
||||
|
||||
this.on('remove', (reaction, user) => {
|
||||
this.total--;
|
||||
if (!this.collected.some(r => r.users.has(user.id))) this.users.delete(user.id);
|
||||
if (!this.collected.some(r => r.users.cache.has(user.id))) this.users.delete(user.id);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class Role extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get members() {
|
||||
return this.guild.members.filter(m => m.roles.has(this.id));
|
||||
return this.guild.members.cache.filter(m => m.roles.cache.has(this.id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ const Webhook = require('./Webhook');
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const Collection = require('../util/Collection');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const MessageStore = require('../stores/MessageStore');
|
||||
const MessageManager = require('../managers/MessageManager');
|
||||
|
||||
/**
|
||||
* Represents a guild text channel on Discord.
|
||||
@@ -20,10 +20,10 @@ class TextChannel extends GuildChannel {
|
||||
constructor(guild, data) {
|
||||
super(guild, data);
|
||||
/**
|
||||
* A collection containing the messages sent to this channel
|
||||
* @type {MessageStore<Snowflake, Message>}
|
||||
* A manager of the messages sent to this channel
|
||||
* @type {MessageManager}
|
||||
*/
|
||||
this.messages = new MessageStore(this);
|
||||
this.messages = new MessageManager(this);
|
||||
this._typing = new Map();
|
||||
}
|
||||
|
||||
|
||||
@@ -119,8 +119,8 @@ class User extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get lastMessage() {
|
||||
const channel = this.client.channels.get(this.lastMessageChannelID);
|
||||
return (channel && channel.messages.get(this.lastMessageID)) || null;
|
||||
const channel = this.client.channels.cache.get(this.lastMessageChannelID);
|
||||
return (channel && channel.messages.cache.get(this.lastMessageID)) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,8 +129,8 @@ class User extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get presence() {
|
||||
for (const guild of this.client.guilds.values()) {
|
||||
if (guild.presences.has(this.id)) return guild.presences.get(this.id);
|
||||
for (const guild of this.client.guilds.cache.values()) {
|
||||
if (guild.presences.cache.has(this.id)) return guild.presences.cache.get(this.id);
|
||||
}
|
||||
return new Presence(this.client, { user: { id: this.id } });
|
||||
}
|
||||
@@ -209,7 +209,7 @@ class User extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get dmChannel() {
|
||||
return this.client.channels.find(c => c.type === 'dm' && c.recipient.id === this.id) || null;
|
||||
return this.client.channels.cache.find(c => c.type === 'dm' && c.recipient.id === this.id) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ class VoiceChannel extends GuildChannel {
|
||||
*/
|
||||
get members() {
|
||||
const coll = new Collection();
|
||||
for (const state of this.guild.voiceStates.values()) {
|
||||
for (const state of this.guild.voiceStates.cache.values()) {
|
||||
if (state.channelID === this.id && state.member) {
|
||||
coll.set(state.id, state.member);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class VoiceState extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get member() {
|
||||
return this.guild.members.get(this.id) || null;
|
||||
return this.guild.members.cache.get(this.id) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ class VoiceState extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get channel() {
|
||||
return this.guild.channels.get(this.channelID) || null;
|
||||
return this.guild.channels.cache.get(this.channelID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,7 +70,7 @@ class Webhook {
|
||||
* The owner of the webhook
|
||||
* @type {?User|Object}
|
||||
*/
|
||||
this.owner = this.client.users ? this.client.users.get(data.user.id) : data.user;
|
||||
this.owner = this.client.users ? this.client.users.cache.get(data.user.id) : data.user;
|
||||
} else {
|
||||
this.owner = null;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class Webhook {
|
||||
query: { wait: true },
|
||||
auth: false,
|
||||
}).then(d => {
|
||||
const channel = this.client.channels ? this.client.channels.get(d.channel_id) : undefined;
|
||||
const channel = this.client.channels ? this.client.channels.cache.get(d.channel_id) : undefined;
|
||||
if (!channel) return d;
|
||||
return channel.messages.add(d, false);
|
||||
});
|
||||
|
||||
@@ -13,10 +13,10 @@ const APIMessage = require('../APIMessage');
|
||||
class TextBasedChannel {
|
||||
constructor() {
|
||||
/**
|
||||
* A collection containing the messages sent to this channel
|
||||
* @type {MessageStore<Snowflake, Message>}
|
||||
* A manager of the messages sent to this channel
|
||||
* @type {MessageManager}
|
||||
*/
|
||||
this.messages = new MessageStore(this);
|
||||
this.messages = new MessageManager(this);
|
||||
|
||||
/**
|
||||
* The ID of the last message in the channel, if one was sent
|
||||
@@ -37,7 +37,7 @@ class TextBasedChannel {
|
||||
* @readonly
|
||||
*/
|
||||
get lastMessage() {
|
||||
return this.messages.get(this.lastMessageID) || null;
|
||||
return this.messages.cache.get(this.lastMessageID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,4 +350,4 @@ class TextBasedChannel {
|
||||
module.exports = TextBasedChannel;
|
||||
|
||||
// Fixes Circular
|
||||
const MessageStore = require('../../stores/MessageStore');
|
||||
const MessageManager = require('../../managers/MessageManager');
|
||||
|
||||
Reference in New Issue
Block a user