diff --git a/packages/discord.js/.eslintrc.json b/packages/discord.js/.eslintrc.json index 8122b17d7..de32e14c9 100644 --- a/packages/discord.js/.eslintrc.json +++ b/packages/discord.js/.eslintrc.json @@ -3,10 +3,10 @@ "extends": ["eslint:recommended", "plugin:prettier/recommended"], "plugins": ["import"], "parserOptions": { - "ecmaVersion": 2021 + "ecmaVersion": 2022 }, "env": { - "es2021": true, + "es2022": true, "node": true }, "rules": { diff --git a/packages/discord.js/src/structures/GuildAuditLogs.js b/packages/discord.js/src/structures/GuildAuditLogs.js index 37fb89cc3..beff6c7e4 100644 --- a/packages/discord.js/src/structures/GuildAuditLogs.js +++ b/packages/discord.js/src/structures/GuildAuditLogs.js @@ -57,6 +57,9 @@ const Targets = { * Audit logs entries are held in this class. */ class GuildAuditLogs { + static Targets = Targets; + static Entry = GuildAuditLogsEntry; + constructor(guild, data) { if (data.users) for (const user of data.users) guild.client.users._add(user); if (data.threads) for (const thread of data.threads) guild.client.channels._add(thread, guild); @@ -522,7 +525,4 @@ class GuildAuditLogsEntry { } } -GuildAuditLogs.Targets = Targets; -GuildAuditLogs.Entry = GuildAuditLogsEntry; - module.exports = GuildAuditLogs; diff --git a/packages/discord.js/src/structures/GuildChannel.js b/packages/discord.js/src/structures/GuildChannel.js index a68cc86fe..8561ec6a3 100644 --- a/packages/discord.js/src/structures/GuildChannel.js +++ b/packages/discord.js/src/structures/GuildChannel.js @@ -120,11 +120,11 @@ class GuildChannel extends Channel { // Handle empty overwrite if ( (!channelVal && - parentVal.deny.bitfield === PermissionsBitField.defaultBit && - parentVal.allow.bitfield === PermissionsBitField.defaultBit) || + parentVal.deny.bitfield === PermissionsBitField.DefaultBit && + parentVal.allow.bitfield === PermissionsBitField.DefaultBit) || (!parentVal && - channelVal.deny.bitfield === PermissionsBitField.defaultBit && - channelVal.allow.bitfield === PermissionsBitField.defaultBit) + channelVal.deny.bitfield === PermissionsBitField.DefaultBit && + channelVal.allow.bitfield === PermissionsBitField.DefaultBit) ) { return true; } @@ -210,12 +210,12 @@ class GuildChannel extends Channel { const overwrites = this.overwritesFor(member, true, roles); return permissions - .remove(overwrites.everyone?.deny ?? PermissionsBitField.defaultBit) - .add(overwrites.everyone?.allow ?? PermissionsBitField.defaultBit) - .remove(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.deny) : PermissionsBitField.defaultBit) - .add(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.allow) : PermissionsBitField.defaultBit) - .remove(overwrites.member?.deny ?? PermissionsBitField.defaultBit) - .add(overwrites.member?.allow ?? PermissionsBitField.defaultBit) + .remove(overwrites.everyone?.deny ?? PermissionsBitField.DefaultBit) + .add(overwrites.everyone?.allow ?? PermissionsBitField.DefaultBit) + .remove(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.deny) : PermissionsBitField.DefaultBit) + .add(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.allow) : PermissionsBitField.DefaultBit) + .remove(overwrites.member?.deny ?? PermissionsBitField.DefaultBit) + .add(overwrites.member?.allow ?? PermissionsBitField.DefaultBit) .freeze(); } @@ -235,10 +235,10 @@ class GuildChannel extends Channel { const roleOverwrites = this.permissionOverwrites.cache.get(role.id); return role.permissions - .remove(everyoneOverwrites?.deny ?? PermissionsBitField.defaultBit) - .add(everyoneOverwrites?.allow ?? PermissionsBitField.defaultBit) - .remove(roleOverwrites?.deny ?? PermissionsBitField.defaultBit) - .add(roleOverwrites?.allow ?? PermissionsBitField.defaultBit) + .remove(everyoneOverwrites?.deny ?? PermissionsBitField.DefaultBit) + .add(everyoneOverwrites?.allow ?? PermissionsBitField.DefaultBit) + .remove(roleOverwrites?.deny ?? PermissionsBitField.DefaultBit) + .add(roleOverwrites?.allow ?? PermissionsBitField.DefaultBit) .freeze(); } diff --git a/packages/discord.js/src/structures/GuildTemplate.js b/packages/discord.js/src/structures/GuildTemplate.js index 9c447f127..60a4dc9ad 100644 --- a/packages/discord.js/src/structures/GuildTemplate.js +++ b/packages/discord.js/src/structures/GuildTemplate.js @@ -11,6 +11,12 @@ const Events = require('../util/Events'); * @extends {Base} */ class GuildTemplate extends Base { + /** + * Regular expression that globally matches guild template links + * @type {RegExp} + */ + static GuildTemplatesPattern = /discord(?:app)?\.(?:com\/template|new)\/([\w-]{2,255})/gi; + constructor(client, data) { super(client); this._patch(data); @@ -230,10 +236,4 @@ class GuildTemplate extends Base { } } -/** - * Regular expression that globally matches guild template links - * @type {RegExp} - */ -GuildTemplate.GUILD_TEMPLATES_PATTERN = /discord(?:app)?\.(?:com\/template|new)\/([\w-]{2,255})/gi; - module.exports = GuildTemplate; diff --git a/packages/discord.js/src/structures/Invite.js b/packages/discord.js/src/structures/Invite.js index 43bc677fa..f2a1c5f2d 100644 --- a/packages/discord.js/src/structures/Invite.js +++ b/packages/discord.js/src/structures/Invite.js @@ -12,6 +12,12 @@ const { Error } = require('../errors'); * @extends {Base} */ class Invite extends Base { + /** + * Regular expression that globally matches Discord invite links + * @type {RegExp} + */ + static InvitesPattern = /discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})/gi; + constructor(client, data) { super(client); this._patch(data); @@ -308,10 +314,4 @@ class Invite extends Base { } } -/** - * Regular expression that globally matches Discord invite links - * @type {RegExp} - */ -Invite.INVITES_PATTERN = /discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})/gi; - module.exports = Invite; diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 91949f0e0..4b0986df6 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -623,7 +623,7 @@ class Message extends Base { get crosspostable() { const bitfield = PermissionFlagsBits.SendMessages | - (this.author.id === this.client.user.id ? PermissionsBitField.defaultBit : PermissionFlagsBits.ManageMessages); + (this.author.id === this.client.user.id ? PermissionsBitField.DefaultBit : PermissionFlagsBits.ManageMessages); const { channel } = this; return Boolean( channel?.type === ChannelType.GuildNews && diff --git a/packages/discord.js/src/structures/MessageMentions.js b/packages/discord.js/src/structures/MessageMentions.js index 6f1588df8..77e1caed6 100644 --- a/packages/discord.js/src/structures/MessageMentions.js +++ b/packages/discord.js/src/structures/MessageMentions.js @@ -7,6 +7,30 @@ const Util = require('../util/Util'); * Keeps track of mentions in a {@link Message}. */ class MessageMentions { + /** + * Regular expression that globally matches `@everyone` and `@here` + * @type {RegExp} + */ + static EveryonePattern = /@(everyone|here)/g; + + /** + * Regular expression that globally matches user mentions like `<@81440962496172032>` + * @type {RegExp} + */ + static UsersPattern = /<@!?(\d{17,19})>/g; + + /** + * Regular expression that globally matches role mentions like `<@&297577916114403338>` + * @type {RegExp} + */ + static RolesPattern = /<@&(\d{17,19})>/g; + + /** + * Regular expression that globally matches channel mentions like `<#222079895583457280>` + * @type {RegExp} + */ + static ChannelsPattern = /<#(\d{17,19})>/g; + constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) { /** * The client the message is from @@ -158,7 +182,7 @@ class MessageMentions { if (this._channels) return this._channels; this._channels = new Collection(); let matches; - while ((matches = this.constructor.CHANNELS_PATTERN.exec(this._content)) !== null) { + while ((matches = this.constructor.ChannelsPattern.exec(this._content)) !== null) { const chan = this.client.channels.cache.get(matches[1]); if (chan) this._channels.set(chan.id, chan); } @@ -212,28 +236,4 @@ class MessageMentions { } } -/** - * Regular expression that globally matches `@everyone` and `@here` - * @type {RegExp} - */ -MessageMentions.EVERYONE_PATTERN = /@(everyone|here)/g; - -/** - * Regular expression that globally matches user mentions like `<@81440962496172032>` - * @type {RegExp} - */ -MessageMentions.USERS_PATTERN = /<@!?(\d{17,19})>/g; - -/** - * Regular expression that globally matches role mentions like `<@&297577916114403338>` - * @type {RegExp} - */ -MessageMentions.ROLES_PATTERN = /<@&(\d{17,19})>/g; - -/** - * Regular expression that globally matches channel mentions like `<#222079895583457280>` - * @type {RegExp} - */ -MessageMentions.CHANNELS_PATTERN = /<#(\d{17,19})>/g; - module.exports = MessageMentions; diff --git a/packages/discord.js/src/structures/PermissionOverwrites.js b/packages/discord.js/src/structures/PermissionOverwrites.js index 31a5be783..49bc066d6 100644 --- a/packages/discord.js/src/structures/PermissionOverwrites.js +++ b/packages/discord.js/src/structures/PermissionOverwrites.js @@ -175,8 +175,8 @@ class PermissionOverwrites extends Base { return { id: overwrite.id, type: overwrite.type, - allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.defaultBit).toString(), - deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.defaultBit).toString(), + allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.DefaultBit).toString(), + deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.DefaultBit).toString(), }; } @@ -187,8 +187,8 @@ class PermissionOverwrites extends Base { return { id: userOrRole.id, type, - allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.defaultBit).toString(), - deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.defaultBit).toString(), + allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.DefaultBit).toString(), + deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.DefaultBit).toString(), }; } } diff --git a/packages/discord.js/src/util/ActivityFlagsBitField.js b/packages/discord.js/src/util/ActivityFlagsBitField.js index fcfb34429..23c37a247 100644 --- a/packages/discord.js/src/util/ActivityFlagsBitField.js +++ b/packages/discord.js/src/util/ActivityFlagsBitField.js @@ -7,7 +7,13 @@ const BitField = require('./BitField'); * Data structure that makes it easy to interact with an {@link Activity#flags} bitfield. * @extends {BitField} */ -class ActivityFlagsBitField extends BitField {} +class ActivityFlagsBitField extends BitField { + /** + * Numeric activity flags. + * @type {ActivityFlags} + */ + static Flags = ActivityFlags; +} /** * @name ActivityFlagsBitField @@ -16,10 +22,4 @@ class ActivityFlagsBitField extends BitField {} * @param {BitFieldResolvable} [bits=0] Bit(s) to read from */ -/** - * Numeric activity flags. - * @type {ActivityFlags} - */ -ActivityFlagsBitField.Flags = ActivityFlags; - module.exports = ActivityFlagsBitField; diff --git a/packages/discord.js/src/util/ApplicationFlagsBitField.js b/packages/discord.js/src/util/ApplicationFlagsBitField.js index 5404c0155..ed867dfba 100644 --- a/packages/discord.js/src/util/ApplicationFlagsBitField.js +++ b/packages/discord.js/src/util/ApplicationFlagsBitField.js @@ -7,7 +7,13 @@ const BitField = require('./BitField'); * Data structure that makes it easy to interact with a {@link ClientApplication#flags} bitfield. * @extends {BitField} */ -class ApplicationFlagsBitField extends BitField {} +class ApplicationFlagsBitField extends BitField { + /** + * Numeric application flags. All available properties: + * @type {ApplicationFlags} + */ + static Flags = ApplicationFlags; +} /** * @name ApplicationFlagsBitField @@ -16,16 +22,4 @@ class ApplicationFlagsBitField extends BitField {} * @param {BitFieldResolvable} [bits=0] Bit(s) to read from */ -/** - * Bitfield of the packed bits - * @type {number} - * @name ApplicationFlagsBitField#bitfield - */ - -/** - * Numeric application flags. All available properties: - * @type {ApplicationFlags} - */ -ApplicationFlagsBitField.Flags = ApplicationFlags; - module.exports = ApplicationFlagsBitField; diff --git a/packages/discord.js/src/util/BitField.js b/packages/discord.js/src/util/BitField.js index c444d2d1a..26dfba1e2 100644 --- a/packages/discord.js/src/util/BitField.js +++ b/packages/discord.js/src/util/BitField.js @@ -7,9 +7,23 @@ const { RangeError } = require('../errors'); */ class BitField { /** - * @param {BitFieldResolvable} [bits=this.constructor.defaultBit] Bit(s) to read from + * Numeric bitfield flags. + * Defined in extension classes + * @type {Object} + * @abstract */ - constructor(bits = this.constructor.defaultBit) { + static Flags = {}; + + /** + * @type {number|bigint} + * @private + */ + static DefaultBit = 0; + + /** + * @param {BitFieldResolvable} [bits=this.constructor.DefaultBit] Bit(s) to read from + */ + constructor(bits = this.constructor.DefaultBit) { /** * Bitfield of the packed bits * @type {number|bigint} @@ -23,7 +37,7 @@ class BitField { * @returns {boolean} */ any(bit) { - return (this.bitfield & this.constructor.resolve(bit)) !== this.constructor.defaultBit; + return (this.bitfield & this.constructor.resolve(bit)) !== this.constructor.DefaultBit; } /** @@ -69,7 +83,7 @@ class BitField { * @returns {BitField} These bits or new BitField if the instance is frozen. */ add(...bits) { - let total = this.constructor.defaultBit; + let total = this.constructor.DefaultBit; for (const bit of bits) { total |= this.constructor.resolve(bit); } @@ -84,7 +98,7 @@ class BitField { * @returns {BitField} These bits or new BitField if the instance is frozen. */ remove(...bits) { - let total = this.constructor.defaultBit; + let total = this.constructor.DefaultBit; for (const bit of bits) { total |= this.constructor.resolve(bit); } @@ -141,30 +155,16 @@ class BitField { * @returns {number|bigint} */ static resolve(bit) { - const { defaultBit } = this; - if (typeof defaultBit === typeof bit && bit >= defaultBit) return bit; + const { DefaultBit } = this; + if (typeof DefaultBit === typeof bit && bit >= DefaultBit) return bit; if (bit instanceof BitField) return bit.bitfield; - if (Array.isArray(bit)) return bit.map(p => this.resolve(p)).reduce((prev, p) => prev | p, defaultBit); + if (Array.isArray(bit)) return bit.map(p => this.resolve(p)).reduce((prev, p) => prev | p, DefaultBit); if (typeof bit === 'string') { if (typeof this.Flags[bit] !== 'undefined') return this.Flags[bit]; - if (!isNaN(bit)) return typeof defaultBit === 'bigint' ? BigInt(bit) : Number(bit); + if (!isNaN(bit)) return typeof DefaultBit === 'bigint' ? BigInt(bit) : Number(bit); } throw new RangeError('BITFIELD_INVALID', bit); } } -/** - * Numeric bitfield flags. - * Defined in extension classes - * @type {Object} - * @abstract - */ -BitField.Flags = {}; - -/** - * @type {number|bigint} - * @private - */ -BitField.defaultBit = 0; - module.exports = BitField; diff --git a/packages/discord.js/src/util/DataResolver.js b/packages/discord.js/src/util/DataResolver.js index e3ab586f4..74387e9fe 100644 --- a/packages/discord.js/src/util/DataResolver.js +++ b/packages/discord.js/src/util/DataResolver.js @@ -43,7 +43,7 @@ class DataResolver extends null { * @returns {string} */ static resolveInviteCode(data) { - return this.resolveCode(data, Invite.INVITES_PATTERN); + return this.resolveCode(data, Invite.InvitesPattern); } /** @@ -53,7 +53,7 @@ class DataResolver extends null { */ static resolveGuildTemplateCode(data) { const GuildTemplate = require('../structures/GuildTemplate'); - return this.resolveCode(data, GuildTemplate.GUILD_TEMPLATES_PATTERN); + return this.resolveCode(data, GuildTemplate.GuildTemplatesPattern); } /** diff --git a/packages/discord.js/src/util/Formatters.js b/packages/discord.js/src/util/Formatters.js index 94c14b15f..5df19687a 100644 --- a/packages/discord.js/src/util/Formatters.js +++ b/packages/discord.js/src/util/Formatters.js @@ -24,185 +24,167 @@ const { /** * Contains various Discord-specific functions for formatting messages. */ -class Formatters extends null {} +class Formatters extends null { + /** + * Formats the content into a block quote. This needs to be at the start of the line for Discord to format it. + * @method blockQuote + * @param {string} content The content to wrap. + * @returns {string} + */ + static blockQuote = blockQuote; -/** - * Formats the content into a block quote. This needs to be at the start of the line for Discord to format it. - * @method blockQuote - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.blockQuote = blockQuote; + /** + * Formats the content into bold text. + * @method bold + * @param {string} content The content to wrap. + * @returns {string} + */ + static bold = bold; -/** - * Formats the content into bold text. - * @method bold - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.bold = bold; + /** + * Formats a channel id into a channel mention. + * @method channelMention + * @param {string} channelId The channel id to format. + * @returns {string} + */ + static channelMention = channelMention; -/** - * Formats a channel id into a channel mention. - * @method channelMention - * @memberof Formatters - * @param {string} channelId The channel id to format. - * @returns {string} - */ -Formatters.channelMention = channelMention; + /** + * Wraps the content inside a code block with an optional language. + * @method codeBlock + * @param {string} contentOrLanguage The language to use, content if a second parameter isn't provided. + * @param {string} [content] The content to wrap. + * @returns {string} + */ + static codeBlock = codeBlock; -/** - * Wraps the content inside a code block with an optional language. - * @method codeBlock - * @memberof Formatters - * @param {string} contentOrLanguage The language to use, content if a second parameter isn't provided. - * @param {string} [content] The content to wrap. - * @returns {string} - */ -Formatters.codeBlock = codeBlock; + /** + * Formats an emoji id into a fully qualified emoji identifier + * @method formatEmoji + * @param {string} emojiId The emoji id to format. + * @param {boolean} [animated] Whether the emoji is animated or not. Defaults to `false` + * @returns {string} + */ + static formatEmoji = formatEmoji; -/** - * Formats an emoji id into a fully qualified emoji identifier - * @method formatEmoji - * @memberof Formatters - * @param {string} emojiId The emoji id to format. - * @param {boolean} [animated] Whether the emoji is animated or not. Defaults to `false` - * @returns {string} - */ -Formatters.formatEmoji = formatEmoji; + /** + * Wraps the URL into `<>`, which stops it from embedding. + * @method hideLinkEmbed + * @param {string} content The content to wrap. + * @returns {string} + */ + static hideLinkEmbed = hideLinkEmbed; -/** - * Wraps the URL into `<>`, which stops it from embedding. - * @method hideLinkEmbed - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.hideLinkEmbed = hideLinkEmbed; + /** + * Formats the content and the URL into a masked URL with an optional title. + * @method hyperlink + * @param {string} content The content to display. + * @param {string} url The URL the content links to. + * @param {string} [title] The title shown when hovering on the masked link. + * @returns {string} + */ + static hyperlink = hyperlink; -/** - * Formats the content and the URL into a masked URL with an optional title. - * @method hyperlink - * @memberof Formatters - * @param {string} content The content to display. - * @param {string} url The URL the content links to. - * @param {string} [title] The title shown when hovering on the masked link. - * @returns {string} - */ -Formatters.hyperlink = hyperlink; + /** + * Wraps the content inside \`backticks\`, which formats it as inline code. + * @method inlineCode + * @param {string} content The content to wrap. + * @returns {string} + */ + static inlineCode = inlineCode; -/** - * Wraps the content inside \`backticks\`, which formats it as inline code. - * @method inlineCode - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.inlineCode = inlineCode; + /** + * Formats the content into italic text. + * @method italic + * @param {string} content The content to wrap. + * @returns {string} + */ + static italic = italic; -/** - * Formats the content into italic text. - * @method italic - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.italic = italic; + /** + * Formats a user id into a member-nickname mention. + * @method memberNicknameMention + * @param {string} memberId The user id to format. + * @returns {string} + */ + static memberNicknameMention = memberNicknameMention; -/** - * Formats a user id into a member-nickname mention. - * @method memberNicknameMention - * @memberof Formatters - * @param {string} memberId The user id to format. - * @returns {string} - */ -Formatters.memberNicknameMention = memberNicknameMention; + /** + * Formats the content into a quote. This needs to be at the start of the line for Discord to format it. + * @method quote + * @param {string} content The content to wrap. + * @returns {string} + */ + static quote = quote; -/** - * Formats the content into a quote. This needs to be at the start of the line for Discord to format it. - * @method quote - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.quote = quote; + /** + * Formats a role id into a role mention. + * @method roleMention + * @param {string} roleId The role id to format. + * @returns {string} + */ + static roleMention = roleMention; -/** - * Formats a role id into a role mention. - * @method roleMention - * @memberof Formatters - * @param {string} roleId The role id to format. - * @returns {string} - */ -Formatters.roleMention = roleMention; + /** + * Formats the content into spoiler text. + * @method spoiler + * @param {string} content The content to spoiler. + * @returns {string} + */ + static spoiler = spoiler; -/** - * Formats the content into spoiler text. - * @method spoiler - * @memberof Formatters - * @param {string} content The content to spoiler. - * @returns {string} - */ -Formatters.spoiler = spoiler; + /** + * Formats the content into strike-through text. + * @method strikethrough + * @param {string} content The content to wrap. + * @returns {string} + */ + static strikethrough = strikethrough; -/** - * Formats the content into strike-through text. - * @method strikethrough - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.strikethrough = strikethrough; + /** + * Formats a date into a short date-time string. + * @method time + * @param {number|Date} [date] The date to format. + * @param {TimestampStylesString} [style] The style to use. + * @returns {string} + */ + static time = time; -/** - * Formats a date into a short date-time string. - * @method time - * @memberof Formatters - * @param {number|Date} [date] The date to format. - * @param {TimestampStylesString} [style] The style to use. - * @returns {string} - */ -Formatters.time = time; + /** + * A message formatting timestamp style, as defined in + * [here](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles). + * * `t` Short time format, consisting of hours and minutes, e.g. 16:20. + * * `T` Long time format, consisting of hours, minutes, and seconds, e.g. 16:20:30. + * * `d` Short date format, consisting of day, month, and year, e.g. 20/04/2021. + * * `D` Long date format, consisting of day, month, and year, e.g. 20 April 2021. + * * `f` Short date-time format, consisting of short date and short time formats, e.g. 20 April 2021 16:20. + * * `F` Long date-time format, consisting of long date and short time formats, e.g. Tuesday, 20 April 2021 16:20. + * * `R` Relative time format, consisting of a relative duration format, e.g. 2 months ago. + * @typedef {string} TimestampStylesString + */ -/** - * A message formatting timestamp style, as defined in - * [here](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles). - * * `t` Short time format, consisting of hours and minutes, e.g. 16:20. - * * `T` Long time format, consisting of hours, minutes, and seconds, e.g. 16:20:30. - * * `d` Short date format, consisting of day, month, and year, e.g. 20/04/2021. - * * `D` Long date format, consisting of day, month, and year, e.g. 20 April 2021. - * * `f` Short date-time format, consisting of short date and short time formats, e.g. 20 April 2021 16:20. - * * `F` Long date-time format, consisting of long date and short time formats, e.g. Tuesday, 20 April 2021 16:20. - * * `R` Relative time format, consisting of a relative duration format, e.g. 2 months ago. - * @typedef {string} TimestampStylesString - */ + /** + * The message formatting timestamp + * [styles](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles) supported by Discord. + * @type {Object} + */ + static TimestampStyles = TimestampStyles; -/** - * The message formatting timestamp - * [styles](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles) supported by Discord. - * @memberof Formatters - * @type {Object} - */ -Formatters.TimestampStyles = TimestampStyles; + /** + * Formats the content into underscored text. + * @method underscore + * @param {string} content The content to wrap. + * @returns {string} + */ + static underscore = underscore; -/** - * Formats the content into underscored text. - * @method underscore - * @memberof Formatters - * @param {string} content The content to wrap. - * @returns {string} - */ -Formatters.underscore = underscore; - -/** - * Formats a user id into a user mention. - * @method userMention - * @memberof Formatters - * @param {string} userId The user id to format. - * @returns {string} - */ -Formatters.userMention = userMention; + /** + * Formats a user id into a user mention. + * @method userMention + * @param {string} userId The user id to format. + * @returns {string} + */ + static userMention = userMention; +} module.exports = Formatters; diff --git a/packages/discord.js/src/util/IntentsBitField.js b/packages/discord.js/src/util/IntentsBitField.js index cc4038388..1ad116324 100644 --- a/packages/discord.js/src/util/IntentsBitField.js +++ b/packages/discord.js/src/util/IntentsBitField.js @@ -6,7 +6,13 @@ const BitField = require('./BitField'); * Data structure that makes it easy to calculate intents. * @extends {BitField} */ -class IntentsBitField extends BitField {} +class IntentsBitField extends BitField { + /** + * Numeric WebSocket intents + * @type {GatewayIntentBits} + */ + static Flags = GatewayIntentBits; +} /** * @name IntentsBitField @@ -24,10 +30,4 @@ class IntentsBitField extends BitField {} * @typedef {string|number|IntentsBitField|IntentsResolvable[]} IntentsResolvable */ -/** - * Numeric WebSocket intents - * @type {GatewayIntentBits} - */ -IntentsBitField.Flags = GatewayIntentBits; - module.exports = IntentsBitField; diff --git a/packages/discord.js/src/util/MessageFlagsBitField.js b/packages/discord.js/src/util/MessageFlagsBitField.js index 57cd83b2c..97d9dacf3 100644 --- a/packages/discord.js/src/util/MessageFlagsBitField.js +++ b/packages/discord.js/src/util/MessageFlagsBitField.js @@ -7,7 +7,13 @@ const BitField = require('./BitField'); * Data structure that makes it easy to interact with a {@link Message#flags} bitfield. * @extends {BitField} */ -class MessageFlagsBitField extends BitField {} +class MessageFlagsBitField extends BitField { + /** + * Numeric message flags. + * @type {MessageFlags} + */ + static Flags = MessageFlags; +} /** * @name MessageFlagsBitField @@ -22,10 +28,4 @@ class MessageFlagsBitField extends BitField {} * @name MessageFlagsBitField#bitfield */ -/** - * Numeric message flags. - * @type {MessageFlags} - */ -MessageFlagsBitField.Flags = MessageFlags; - module.exports = MessageFlagsBitField; diff --git a/packages/discord.js/src/util/Options.js b/packages/discord.js/src/util/Options.js index 01507797d..475dd8c3b 100644 --- a/packages/discord.js/src/util/Options.js +++ b/packages/discord.js/src/util/Options.js @@ -74,11 +74,11 @@ class Options extends null { return { waitGuildTimeout: 15_000, shardCount: 1, - makeCache: this.cacheWithLimits(this.defaultMakeCacheSettings), + makeCache: this.cacheWithLimits(this.DefaultMakeCacheSettings), partials: [], failIfNotExists: true, presence: {}, - sweepers: this.defaultSweeperSettings, + sweepers: this.DefaultSweeperSettings, ws: { large_threshold: 50, compress: false, @@ -153,30 +153,32 @@ class Options extends null { * * `GuildChannelManager` - Sweep archived threads * * `ThreadManager` - Sweep archived threads * If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g. - * `makeCache: Options.cacheWithLimits({ ...Options.defaultMakeCacheSettings, ReactionManager: 0 })` + * `makeCache: Options.cacheWithLimits({ ...Options.DefaultMakeCacheSettings, ReactionManager: 0 })` * @type {Object} */ - static get defaultMakeCacheSettings() { + static get DefaultMakeCacheSettings() { return { MessageManager: 200, }; } -} -/** - * The default settings passed to {@link Options.sweepers} (for v14). - * The sweepers that this changes are: - * * `threads` - Sweep archived threads every hour, removing those archived more than 4 hours ago - * If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g. - * `sweepers: { ...Options.defaultSweeperSettings, messages: { interval: 300, lifetime: 600 } })` - * @type {SweeperOptions} - */ -Options.defaultSweeperSettings = { - threads: { - interval: 3600, - lifetime: 14400, - }, -}; + /** + * The default settings passed to {@link Options.sweepers} (for v14). + * The sweepers that this changes are: + * * `threads` - Sweep archived threads every hour, removing those archived more than 4 hours ago + * If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g. + * `sweepers: { ...Options.DefaultSweeperSettings, messages: { interval: 300, lifetime: 600 } })` + * @type {SweeperOptions} + */ + static get DefaultSweeperSettings() { + return { + threads: { + interval: 3600, + lifetime: 14400, + }, + }; + } +} module.exports = Options; diff --git a/packages/discord.js/src/util/PermissionsBitField.js b/packages/discord.js/src/util/PermissionsBitField.js index 7eb72b787..75d18f168 100644 --- a/packages/discord.js/src/util/PermissionsBitField.js +++ b/packages/discord.js/src/util/PermissionsBitField.js @@ -10,6 +10,34 @@ const BitField = require('./BitField'); * @extends {BitField} */ class PermissionsBitField extends BitField { + /** + * Numeric permission flags. + * @type {PermissionFlagsBits} + * @see {@link https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags} + */ + static Flags = PermissionFlagsBits; + + /** + * Bitfield representing every permission combined + * @type {bigint} + */ + static All = Object.values(PermissionFlagsBits).reduce((all, p) => all | p, 0n); + + /** + * Bitfield representing the default permissions for users + * @type {bigint} + */ + static Default = BigInt(104324673); + + /** + * Bitfield representing the permissions required for moderators of stage channels + * @type {bigint} + */ + static StageModerator = + PermissionFlagsBits.ManageChannels | PermissionFlagsBits.MuteMembers | PermissionFlagsBits.MoveMembers; + + static DefaultBit = BigInt(0); + /** * Bitfield of the packed bits * @type {bigint} @@ -64,32 +92,4 @@ class PermissionsBitField extends BitField { } } -/** - * Numeric permission flags. - * @type {PermissionFlagsBits} - * @see {@link https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags} - */ -PermissionsBitField.Flags = PermissionFlagsBits; - -/** - * Bitfield representing every permission combined - * @type {bigint} - */ -PermissionsBitField.All = Object.values(PermissionFlagsBits).reduce((all, p) => all | p, 0n); - -/** - * Bitfield representing the default permissions for users - * @type {bigint} - */ -PermissionsBitField.Default = BigInt(104324673); - -/** - * Bitfield representing the permissions required for moderators of stage channels - * @type {bigint} - */ -PermissionsBitField.StageModerator = - PermissionFlagsBits.ManageChannels | PermissionFlagsBits.MuteMembers | PermissionFlagsBits.MoveMembers; - -PermissionsBitField.defaultBit = BigInt(0); - module.exports = PermissionsBitField; diff --git a/packages/discord.js/src/util/SystemChannelFlagsBitField.js b/packages/discord.js/src/util/SystemChannelFlagsBitField.js index e7c28ea66..eead2639b 100644 --- a/packages/discord.js/src/util/SystemChannelFlagsBitField.js +++ b/packages/discord.js/src/util/SystemChannelFlagsBitField.js @@ -9,7 +9,13 @@ const BitField = require('./BitField'); * and by setting their corresponding flags you are disabling them * @extends {BitField} */ -class SystemChannelFlagsBitField extends BitField {} +class SystemChannelFlagsBitField extends BitField { + /** + * Numeric system channel flags. + * @type {GuildSystemChannelFlags} + */ + static Flags = GuildSystemChannelFlags; +} /** * @name SystemChannelFlagsBitField @@ -33,10 +39,4 @@ class SystemChannelFlagsBitField extends BitField {} * @typedef {string|number|SystemChannelFlagsBitField|SystemChannelFlagsResolvable[]} SystemChannelFlagsResolvable */ -/** - * Numeric system channel flags. - * @type {GuildSystemChannelFlags} - */ -SystemChannelFlagsBitField.Flags = GuildSystemChannelFlags; - module.exports = SystemChannelFlagsBitField; diff --git a/packages/discord.js/src/util/ThreadMemberFlagsBitField.js b/packages/discord.js/src/util/ThreadMemberFlagsBitField.js index 4f94b521e..969db0c9b 100644 --- a/packages/discord.js/src/util/ThreadMemberFlagsBitField.js +++ b/packages/discord.js/src/util/ThreadMemberFlagsBitField.js @@ -6,7 +6,13 @@ const BitField = require('./BitField'); * Data structure that makes it easy to interact with a {@link ThreadMember#flags} bitfield. * @extends {BitField} */ -class ThreadMemberFlagsBitField extends BitField {} +class ThreadMemberFlagsBitField extends BitField { + /** + * Numeric thread member flags. There are currently no bitflags relevant to bots for this. + * @type {Object} + */ + static Flags = {}; +} /** * @name ThreadMemberFlagsBitField @@ -21,10 +27,4 @@ class ThreadMemberFlagsBitField extends BitField {} * @name ThreadMemberFlagsBitField#bitfield */ -/** - * Numeric thread member flags. There are currently no bitflags relevant to bots for this. - * @type {Object} - */ -ThreadMemberFlagsBitField.Flags = {}; - module.exports = ThreadMemberFlagsBitField; diff --git a/packages/discord.js/src/util/UserFlagsBitField.js b/packages/discord.js/src/util/UserFlagsBitField.js index 91bce5098..7ab9616d1 100644 --- a/packages/discord.js/src/util/UserFlagsBitField.js +++ b/packages/discord.js/src/util/UserFlagsBitField.js @@ -7,7 +7,13 @@ const BitField = require('./BitField'); * Data structure that makes it easy to interact with a {@link User#flags} bitfield. * @extends {BitField} */ -class UserFlagsBitField extends BitField {} +class UserFlagsBitField extends BitField { + /** + * Numeric user flags. + * @type {UserFlags} + */ + static Flags = UserFlags; +} /** * @name UserFlagsBitField @@ -22,10 +28,4 @@ class UserFlagsBitField extends BitField {} * @name UserFlagsBitField#bitfield */ -/** - * Numeric user flags. - * @type {UserFlags} - */ -UserFlagsBitField.Flags = UserFlags; - module.exports = UserFlagsBitField; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 4967e9932..0536f4ba8 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -774,8 +774,8 @@ export class ClientUser extends User { export class Options extends null { private constructor(); - public static defaultMakeCacheSettings: CacheWithLimitsOptions; - public static defaultSweeperSettings: SweeperOptions; + public static get DefaultMakeCacheSettings(): CacheWithLimitsOptions; + public static get DefaultSweeperSettings(): SweeperOptions; public static createDefault(): ClientOptions; public static cacheWithLimits(settings?: CacheWithLimitsOptions): CacheFactory; public static cacheEverything(): CacheFactory; @@ -1356,7 +1356,7 @@ export class GuildTemplate extends Base { public delete(): Promise; public edit(options?: EditGuildTemplateOptions): Promise; public sync(): Promise; - public static GUILD_TEMPLATES_PATTERN: RegExp; + public static GuildTemplatesPattern: RegExp; } export class GuildPreviewEmoji extends BaseGuildEmoji { @@ -1525,7 +1525,7 @@ export class Invite extends Base { public delete(reason?: string): Promise; public toJSON(): unknown; public toString(): string; - public static INVITES_PATTERN: RegExp; + public static InvitesPattern: RegExp; /** @deprecated */ public stageInstance: InviteStageInstance | null; public guildScheduledEvent: GuildScheduledEvent | null; @@ -1773,10 +1773,10 @@ export class MessageMentions { public crosspostedChannels: Collection; public toJSON(): unknown; - public static CHANNELS_PATTERN: RegExp; - public static EVERYONE_PATTERN: RegExp; - public static ROLES_PATTERN: RegExp; - public static USERS_PATTERN: RegExp; + public static ChannelsPattern: RegExp; + public static EveryonePattern: RegExp; + public static RolesPattern: RegExp; + public static UsersPattern: RegExp; } export class MessagePayload {