refactor: use static fields (#7701)

* refactor: use static fields

* chore: refactor missed areas

* chore: remove memberof docs

* chore: make type changes
This commit is contained in:
Suneet Tipirneni
2022-03-23 21:38:05 -04:00
committed by GitHub
parent 72577c4bfd
commit e805777a7a
21 changed files with 336 additions and 358 deletions

View File

@@ -3,10 +3,10 @@
"extends": ["eslint:recommended", "plugin:prettier/recommended"], "extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["import"], "plugins": ["import"],
"parserOptions": { "parserOptions": {
"ecmaVersion": 2021 "ecmaVersion": 2022
}, },
"env": { "env": {
"es2021": true, "es2022": true,
"node": true "node": true
}, },
"rules": { "rules": {

View File

@@ -57,6 +57,9 @@ const Targets = {
* Audit logs entries are held in this class. * Audit logs entries are held in this class.
*/ */
class GuildAuditLogs { class GuildAuditLogs {
static Targets = Targets;
static Entry = GuildAuditLogsEntry;
constructor(guild, data) { constructor(guild, data) {
if (data.users) for (const user of data.users) guild.client.users._add(user); if (data.users) for (const user of data.users) guild.client.users._add(user);
if (data.threads) for (const thread of data.threads) guild.client.channels._add(thread, guild); 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; module.exports = GuildAuditLogs;

View File

@@ -120,11 +120,11 @@ class GuildChannel extends Channel {
// Handle empty overwrite // Handle empty overwrite
if ( if (
(!channelVal && (!channelVal &&
parentVal.deny.bitfield === PermissionsBitField.defaultBit && parentVal.deny.bitfield === PermissionsBitField.DefaultBit &&
parentVal.allow.bitfield === PermissionsBitField.defaultBit) || parentVal.allow.bitfield === PermissionsBitField.DefaultBit) ||
(!parentVal && (!parentVal &&
channelVal.deny.bitfield === PermissionsBitField.defaultBit && channelVal.deny.bitfield === PermissionsBitField.DefaultBit &&
channelVal.allow.bitfield === PermissionsBitField.defaultBit) channelVal.allow.bitfield === PermissionsBitField.DefaultBit)
) { ) {
return true; return true;
} }
@@ -210,12 +210,12 @@ class GuildChannel extends Channel {
const overwrites = this.overwritesFor(member, true, roles); const overwrites = this.overwritesFor(member, true, roles);
return permissions return permissions
.remove(overwrites.everyone?.deny ?? PermissionsBitField.defaultBit) .remove(overwrites.everyone?.deny ?? PermissionsBitField.DefaultBit)
.add(overwrites.everyone?.allow ?? PermissionsBitField.defaultBit) .add(overwrites.everyone?.allow ?? PermissionsBitField.DefaultBit)
.remove(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.deny) : 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) .add(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.allow) : PermissionsBitField.DefaultBit)
.remove(overwrites.member?.deny ?? PermissionsBitField.defaultBit) .remove(overwrites.member?.deny ?? PermissionsBitField.DefaultBit)
.add(overwrites.member?.allow ?? PermissionsBitField.defaultBit) .add(overwrites.member?.allow ?? PermissionsBitField.DefaultBit)
.freeze(); .freeze();
} }
@@ -235,10 +235,10 @@ class GuildChannel extends Channel {
const roleOverwrites = this.permissionOverwrites.cache.get(role.id); const roleOverwrites = this.permissionOverwrites.cache.get(role.id);
return role.permissions return role.permissions
.remove(everyoneOverwrites?.deny ?? PermissionsBitField.defaultBit) .remove(everyoneOverwrites?.deny ?? PermissionsBitField.DefaultBit)
.add(everyoneOverwrites?.allow ?? PermissionsBitField.defaultBit) .add(everyoneOverwrites?.allow ?? PermissionsBitField.DefaultBit)
.remove(roleOverwrites?.deny ?? PermissionsBitField.defaultBit) .remove(roleOverwrites?.deny ?? PermissionsBitField.DefaultBit)
.add(roleOverwrites?.allow ?? PermissionsBitField.defaultBit) .add(roleOverwrites?.allow ?? PermissionsBitField.DefaultBit)
.freeze(); .freeze();
} }

View File

@@ -11,6 +11,12 @@ const Events = require('../util/Events');
* @extends {Base} * @extends {Base}
*/ */
class GuildTemplate 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) { constructor(client, data) {
super(client); super(client);
this._patch(data); 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; module.exports = GuildTemplate;

View File

@@ -12,6 +12,12 @@ const { Error } = require('../errors');
* @extends {Base} * @extends {Base}
*/ */
class Invite 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) { constructor(client, data) {
super(client); super(client);
this._patch(data); 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; module.exports = Invite;

View File

@@ -623,7 +623,7 @@ class Message extends Base {
get crosspostable() { get crosspostable() {
const bitfield = const bitfield =
PermissionFlagsBits.SendMessages | 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; const { channel } = this;
return Boolean( return Boolean(
channel?.type === ChannelType.GuildNews && channel?.type === ChannelType.GuildNews &&

View File

@@ -7,6 +7,30 @@ const Util = require('../util/Util');
* Keeps track of mentions in a {@link Message}. * Keeps track of mentions in a {@link Message}.
*/ */
class MessageMentions { 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) { constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) {
/** /**
* The client the message is from * The client the message is from
@@ -158,7 +182,7 @@ class MessageMentions {
if (this._channels) return this._channels; if (this._channels) return this._channels;
this._channels = new Collection(); this._channels = new Collection();
let matches; 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]); const chan = this.client.channels.cache.get(matches[1]);
if (chan) this._channels.set(chan.id, chan); 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; module.exports = MessageMentions;

View File

@@ -175,8 +175,8 @@ class PermissionOverwrites extends Base {
return { return {
id: overwrite.id, id: overwrite.id,
type: overwrite.type, type: overwrite.type,
allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.defaultBit).toString(), allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.DefaultBit).toString(),
deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.defaultBit).toString(), deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.DefaultBit).toString(),
}; };
} }
@@ -187,8 +187,8 @@ class PermissionOverwrites extends Base {
return { return {
id: userOrRole.id, id: userOrRole.id,
type, type,
allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.defaultBit).toString(), allow: PermissionsBitField.resolve(overwrite.allow ?? PermissionsBitField.DefaultBit).toString(),
deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.defaultBit).toString(), deny: PermissionsBitField.resolve(overwrite.deny ?? PermissionsBitField.DefaultBit).toString(),
}; };
} }
} }

View File

@@ -7,7 +7,13 @@ const BitField = require('./BitField');
* Data structure that makes it easy to interact with an {@link Activity#flags} bitfield. * Data structure that makes it easy to interact with an {@link Activity#flags} bitfield.
* @extends {BitField} * @extends {BitField}
*/ */
class ActivityFlagsBitField extends BitField {} class ActivityFlagsBitField extends BitField {
/**
* Numeric activity flags.
* @type {ActivityFlags}
*/
static Flags = ActivityFlags;
}
/** /**
* @name ActivityFlagsBitField * @name ActivityFlagsBitField
@@ -16,10 +22,4 @@ class ActivityFlagsBitField extends BitField {}
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from * @param {BitFieldResolvable} [bits=0] Bit(s) to read from
*/ */
/**
* Numeric activity flags.
* @type {ActivityFlags}
*/
ActivityFlagsBitField.Flags = ActivityFlags;
module.exports = ActivityFlagsBitField; module.exports = ActivityFlagsBitField;

View File

@@ -7,7 +7,13 @@ const BitField = require('./BitField');
* Data structure that makes it easy to interact with a {@link ClientApplication#flags} bitfield. * Data structure that makes it easy to interact with a {@link ClientApplication#flags} bitfield.
* @extends {BitField} * @extends {BitField}
*/ */
class ApplicationFlagsBitField extends BitField {} class ApplicationFlagsBitField extends BitField {
/**
* Numeric application flags. All available properties:
* @type {ApplicationFlags}
*/
static Flags = ApplicationFlags;
}
/** /**
* @name ApplicationFlagsBitField * @name ApplicationFlagsBitField
@@ -16,16 +22,4 @@ class ApplicationFlagsBitField extends BitField {}
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from * @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; module.exports = ApplicationFlagsBitField;

View File

@@ -7,9 +7,23 @@ const { RangeError } = require('../errors');
*/ */
class BitField { class BitField {
/** /**
* @param {BitFieldResolvable} [bits=this.constructor.defaultBit] Bit(s) to read from * Numeric bitfield flags.
* <info>Defined in extension classes</info>
* @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 * Bitfield of the packed bits
* @type {number|bigint} * @type {number|bigint}
@@ -23,7 +37,7 @@ class BitField {
* @returns {boolean} * @returns {boolean}
*/ */
any(bit) { 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. * @returns {BitField} These bits or new BitField if the instance is frozen.
*/ */
add(...bits) { add(...bits) {
let total = this.constructor.defaultBit; let total = this.constructor.DefaultBit;
for (const bit of bits) { for (const bit of bits) {
total |= this.constructor.resolve(bit); total |= this.constructor.resolve(bit);
} }
@@ -84,7 +98,7 @@ class BitField {
* @returns {BitField} These bits or new BitField if the instance is frozen. * @returns {BitField} These bits or new BitField if the instance is frozen.
*/ */
remove(...bits) { remove(...bits) {
let total = this.constructor.defaultBit; let total = this.constructor.DefaultBit;
for (const bit of bits) { for (const bit of bits) {
total |= this.constructor.resolve(bit); total |= this.constructor.resolve(bit);
} }
@@ -141,30 +155,16 @@ class BitField {
* @returns {number|bigint} * @returns {number|bigint}
*/ */
static resolve(bit) { static resolve(bit) {
const { defaultBit } = this; const { DefaultBit } = this;
if (typeof defaultBit === typeof bit && bit >= defaultBit) return bit; if (typeof DefaultBit === typeof bit && bit >= DefaultBit) return bit;
if (bit instanceof BitField) return bit.bitfield; 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 bit === 'string') {
if (typeof this.Flags[bit] !== 'undefined') return this.Flags[bit]; 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); throw new RangeError('BITFIELD_INVALID', bit);
} }
} }
/**
* Numeric bitfield flags.
* <info>Defined in extension classes</info>
* @type {Object}
* @abstract
*/
BitField.Flags = {};
/**
* @type {number|bigint}
* @private
*/
BitField.defaultBit = 0;
module.exports = BitField; module.exports = BitField;

View File

@@ -43,7 +43,7 @@ class DataResolver extends null {
* @returns {string} * @returns {string}
*/ */
static resolveInviteCode(data) { 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) { static resolveGuildTemplateCode(data) {
const GuildTemplate = require('../structures/GuildTemplate'); const GuildTemplate = require('../structures/GuildTemplate');
return this.resolveCode(data, GuildTemplate.GUILD_TEMPLATES_PATTERN); return this.resolveCode(data, GuildTemplate.GuildTemplatesPattern);
} }
/** /**

View File

@@ -24,185 +24,167 @@ const {
/** /**
* Contains various Discord-specific functions for formatting messages. * 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. * Formats the content into bold text.
* @method blockQuote * @method bold
* @memberof Formatters * @param {string} content The content to wrap.
* @param {string} content The content to wrap. * @returns {string}
* @returns {string} */
*/ static bold = bold;
Formatters.blockQuote = blockQuote;
/** /**
* Formats the content into bold text. * Formats a channel id into a channel mention.
* @method bold * @method channelMention
* @memberof Formatters * @param {string} channelId The channel id to format.
* @param {string} content The content to wrap. * @returns {string}
* @returns {string} */
*/ static channelMention = channelMention;
Formatters.bold = bold;
/** /**
* Formats a channel id into a channel mention. * Wraps the content inside a code block with an optional language.
* @method channelMention * @method codeBlock
* @memberof Formatters * @param {string} contentOrLanguage The language to use, content if a second parameter isn't provided.
* @param {string} channelId The channel id to format. * @param {string} [content] The content to wrap.
* @returns {string} * @returns {string}
*/ */
Formatters.channelMention = channelMention; static codeBlock = codeBlock;
/** /**
* Wraps the content inside a code block with an optional language. * Formats an emoji id into a fully qualified emoji identifier
* @method codeBlock * @method formatEmoji
* @memberof Formatters * @param {string} emojiId The emoji id to format.
* @param {string} contentOrLanguage The language to use, content if a second parameter isn't provided. * @param {boolean} [animated] Whether the emoji is animated or not. Defaults to `false`
* @param {string} [content] The content to wrap. * @returns {string}
* @returns {string} */
*/ static formatEmoji = formatEmoji;
Formatters.codeBlock = codeBlock;
/** /**
* Formats an emoji id into a fully qualified emoji identifier * Wraps the URL into `<>`, which stops it from embedding.
* @method formatEmoji * @method hideLinkEmbed
* @memberof Formatters * @param {string} content The content to wrap.
* @param {string} emojiId The emoji id to format. * @returns {string}
* @param {boolean} [animated] Whether the emoji is animated or not. Defaults to `false` */
* @returns {string} static hideLinkEmbed = hideLinkEmbed;
*/
Formatters.formatEmoji = formatEmoji;
/** /**
* Wraps the URL into `<>`, which stops it from embedding. * Formats the content and the URL into a masked URL with an optional title.
* @method hideLinkEmbed * @method hyperlink
* @memberof Formatters * @param {string} content The content to display.
* @param {string} content The content to wrap. * @param {string} url The URL the content links to.
* @returns {string} * @param {string} [title] The title shown when hovering on the masked link.
*/ * @returns {string}
Formatters.hideLinkEmbed = hideLinkEmbed; */
static hyperlink = hyperlink;
/** /**
* Formats the content and the URL into a masked URL with an optional title. * Wraps the content inside \`backticks\`, which formats it as inline code.
* @method hyperlink * @method inlineCode
* @memberof Formatters * @param {string} content The content to wrap.
* @param {string} content The content to display. * @returns {string}
* @param {string} url The URL the content links to. */
* @param {string} [title] The title shown when hovering on the masked link. static inlineCode = inlineCode;
* @returns {string}
*/
Formatters.hyperlink = hyperlink;
/** /**
* Wraps the content inside \`backticks\`, which formats it as inline code. * Formats the content into italic text.
* @method inlineCode * @method italic
* @memberof Formatters * @param {string} content The content to wrap.
* @param {string} content The content to wrap. * @returns {string}
* @returns {string} */
*/ static italic = italic;
Formatters.inlineCode = inlineCode;
/** /**
* Formats the content into italic text. * Formats a user id into a member-nickname mention.
* @method italic * @method memberNicknameMention
* @memberof Formatters * @param {string} memberId The user id to format.
* @param {string} content The content to wrap. * @returns {string}
* @returns {string} */
*/ static memberNicknameMention = memberNicknameMention;
Formatters.italic = italic;
/** /**
* Formats a user id into a member-nickname mention. * Formats the content into a quote. This needs to be at the start of the line for Discord to format it.
* @method memberNicknameMention * @method quote
* @memberof Formatters * @param {string} content The content to wrap.
* @param {string} memberId The user id to format. * @returns {string}
* @returns {string} */
*/ static quote = quote;
Formatters.memberNicknameMention = memberNicknameMention;
/** /**
* Formats the content into a quote. This needs to be at the start of the line for Discord to format it. * Formats a role id into a role mention.
* @method quote * @method roleMention
* @memberof Formatters * @param {string} roleId The role id to format.
* @param {string} content The content to wrap. * @returns {string}
* @returns {string} */
*/ static roleMention = roleMention;
Formatters.quote = quote;
/** /**
* Formats a role id into a role mention. * Formats the content into spoiler text.
* @method roleMention * @method spoiler
* @memberof Formatters * @param {string} content The content to spoiler.
* @param {string} roleId The role id to format. * @returns {string}
* @returns {string} */
*/ static spoiler = spoiler;
Formatters.roleMention = roleMention;
/** /**
* Formats the content into spoiler text. * Formats the content into strike-through text.
* @method spoiler * @method strikethrough
* @memberof Formatters * @param {string} content The content to wrap.
* @param {string} content The content to spoiler. * @returns {string}
* @returns {string} */
*/ static strikethrough = strikethrough;
Formatters.spoiler = spoiler;
/** /**
* Formats the content into strike-through text. * Formats a date into a short date-time string.
* @method strikethrough * @method time
* @memberof Formatters * @param {number|Date} [date] The date to format.
* @param {string} content The content to wrap. * @param {TimestampStylesString} [style] The style to use.
* @returns {string} * @returns {string}
*/ */
Formatters.strikethrough = strikethrough; static time = time;
/** /**
* Formats a date into a short date-time string. * A message formatting timestamp style, as defined in
* @method time * [here](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles).
* @memberof Formatters * * `t` Short time format, consisting of hours and minutes, e.g. 16:20.
* @param {number|Date} [date] The date to format. * * `T` Long time format, consisting of hours, minutes, and seconds, e.g. 16:20:30.
* @param {TimestampStylesString} [style] The style to use. * * `d` Short date format, consisting of day, month, and year, e.g. 20/04/2021.
* @returns {string} * * `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.
Formatters.time = time; * * `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 * The message formatting timestamp
* [here](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles). * [styles](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles) supported by Discord.
* * `t` Short time format, consisting of hours and minutes, e.g. 16:20. * @type {Object<string, TimestampStylesString>}
* * `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. static TimestampStyles = TimestampStyles;
* * `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 * Formats the content into underscored text.
* [styles](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles) supported by Discord. * @method underscore
* @memberof Formatters * @param {string} content The content to wrap.
* @type {Object<string, TimestampStylesString>} * @returns {string}
*/ */
Formatters.TimestampStyles = TimestampStyles; static underscore = underscore;
/** /**
* Formats the content into underscored text. * Formats a user id into a user mention.
* @method underscore * @method userMention
* @memberof Formatters * @param {string} userId The user id to format.
* @param {string} content The content to wrap. * @returns {string}
* @returns {string} */
*/ static userMention = userMention;
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;
module.exports = Formatters; module.exports = Formatters;

View File

@@ -6,7 +6,13 @@ const BitField = require('./BitField');
* Data structure that makes it easy to calculate intents. * Data structure that makes it easy to calculate intents.
* @extends {BitField} * @extends {BitField}
*/ */
class IntentsBitField extends BitField {} class IntentsBitField extends BitField {
/**
* Numeric WebSocket intents
* @type {GatewayIntentBits}
*/
static Flags = GatewayIntentBits;
}
/** /**
* @name IntentsBitField * @name IntentsBitField
@@ -24,10 +30,4 @@ class IntentsBitField extends BitField {}
* @typedef {string|number|IntentsBitField|IntentsResolvable[]} IntentsResolvable * @typedef {string|number|IntentsBitField|IntentsResolvable[]} IntentsResolvable
*/ */
/**
* Numeric WebSocket intents
* @type {GatewayIntentBits}
*/
IntentsBitField.Flags = GatewayIntentBits;
module.exports = IntentsBitField; module.exports = IntentsBitField;

View File

@@ -7,7 +7,13 @@ const BitField = require('./BitField');
* Data structure that makes it easy to interact with a {@link Message#flags} bitfield. * Data structure that makes it easy to interact with a {@link Message#flags} bitfield.
* @extends {BitField} * @extends {BitField}
*/ */
class MessageFlagsBitField extends BitField {} class MessageFlagsBitField extends BitField {
/**
* Numeric message flags.
* @type {MessageFlags}
*/
static Flags = MessageFlags;
}
/** /**
* @name MessageFlagsBitField * @name MessageFlagsBitField
@@ -22,10 +28,4 @@ class MessageFlagsBitField extends BitField {}
* @name MessageFlagsBitField#bitfield * @name MessageFlagsBitField#bitfield
*/ */
/**
* Numeric message flags.
* @type {MessageFlags}
*/
MessageFlagsBitField.Flags = MessageFlags;
module.exports = MessageFlagsBitField; module.exports = MessageFlagsBitField;

View File

@@ -74,11 +74,11 @@ class Options extends null {
return { return {
waitGuildTimeout: 15_000, waitGuildTimeout: 15_000,
shardCount: 1, shardCount: 1,
makeCache: this.cacheWithLimits(this.defaultMakeCacheSettings), makeCache: this.cacheWithLimits(this.DefaultMakeCacheSettings),
partials: [], partials: [],
failIfNotExists: true, failIfNotExists: true,
presence: {}, presence: {},
sweepers: this.defaultSweeperSettings, sweepers: this.DefaultSweeperSettings,
ws: { ws: {
large_threshold: 50, large_threshold: 50,
compress: false, compress: false,
@@ -153,30 +153,32 @@ class Options extends null {
* * `GuildChannelManager` - Sweep archived threads * * `GuildChannelManager` - Sweep archived threads
* * `ThreadManager` - Sweep archived threads * * `ThreadManager` - Sweep archived threads
* <info>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. * <info>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 })`</info> * `makeCache: Options.cacheWithLimits({ ...Options.DefaultMakeCacheSettings, ReactionManager: 0 })`</info>
* @type {Object<string, LimitedCollectionOptions|number>} * @type {Object<string, LimitedCollectionOptions|number>}
*/ */
static get defaultMakeCacheSettings() { static get DefaultMakeCacheSettings() {
return { return {
MessageManager: 200, MessageManager: 200,
}; };
} }
}
/** /**
* The default settings passed to {@link Options.sweepers} (for v14). * The default settings passed to {@link Options.sweepers} (for v14).
* The sweepers that this changes are: * The sweepers that this changes are:
* * `threads` - Sweep archived threads every hour, removing those archived more than 4 hours ago * * `threads` - Sweep archived threads every hour, removing those archived more than 4 hours ago
* <info>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. * <info>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 } })`</info> * `sweepers: { ...Options.DefaultSweeperSettings, messages: { interval: 300, lifetime: 600 } })`</info>
* @type {SweeperOptions} * @type {SweeperOptions}
*/ */
Options.defaultSweeperSettings = { static get DefaultSweeperSettings() {
threads: { return {
interval: 3600, threads: {
lifetime: 14400, interval: 3600,
}, lifetime: 14400,
}; },
};
}
}
module.exports = Options; module.exports = Options;

View File

@@ -10,6 +10,34 @@ const BitField = require('./BitField');
* @extends {BitField} * @extends {BitField}
*/ */
class PermissionsBitField 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 * Bitfield of the packed bits
* @type {bigint} * @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; module.exports = PermissionsBitField;

View File

@@ -9,7 +9,13 @@ const BitField = require('./BitField');
* and by setting their corresponding flags you are disabling them</info> * and by setting their corresponding flags you are disabling them</info>
* @extends {BitField} * @extends {BitField}
*/ */
class SystemChannelFlagsBitField extends BitField {} class SystemChannelFlagsBitField extends BitField {
/**
* Numeric system channel flags.
* @type {GuildSystemChannelFlags}
*/
static Flags = GuildSystemChannelFlags;
}
/** /**
* @name SystemChannelFlagsBitField * @name SystemChannelFlagsBitField
@@ -33,10 +39,4 @@ class SystemChannelFlagsBitField extends BitField {}
* @typedef {string|number|SystemChannelFlagsBitField|SystemChannelFlagsResolvable[]} SystemChannelFlagsResolvable * @typedef {string|number|SystemChannelFlagsBitField|SystemChannelFlagsResolvable[]} SystemChannelFlagsResolvable
*/ */
/**
* Numeric system channel flags.
* @type {GuildSystemChannelFlags}
*/
SystemChannelFlagsBitField.Flags = GuildSystemChannelFlags;
module.exports = SystemChannelFlagsBitField; module.exports = SystemChannelFlagsBitField;

View File

@@ -6,7 +6,13 @@ const BitField = require('./BitField');
* Data structure that makes it easy to interact with a {@link ThreadMember#flags} bitfield. * Data structure that makes it easy to interact with a {@link ThreadMember#flags} bitfield.
* @extends {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<string, number>}
*/
static Flags = {};
}
/** /**
* @name ThreadMemberFlagsBitField * @name ThreadMemberFlagsBitField
@@ -21,10 +27,4 @@ class ThreadMemberFlagsBitField extends BitField {}
* @name ThreadMemberFlagsBitField#bitfield * @name ThreadMemberFlagsBitField#bitfield
*/ */
/**
* Numeric thread member flags. There are currently no bitflags relevant to bots for this.
* @type {Object<string, number>}
*/
ThreadMemberFlagsBitField.Flags = {};
module.exports = ThreadMemberFlagsBitField; module.exports = ThreadMemberFlagsBitField;

View File

@@ -7,7 +7,13 @@ const BitField = require('./BitField');
* Data structure that makes it easy to interact with a {@link User#flags} bitfield. * Data structure that makes it easy to interact with a {@link User#flags} bitfield.
* @extends {BitField} * @extends {BitField}
*/ */
class UserFlagsBitField extends BitField {} class UserFlagsBitField extends BitField {
/**
* Numeric user flags.
* @type {UserFlags}
*/
static Flags = UserFlags;
}
/** /**
* @name UserFlagsBitField * @name UserFlagsBitField
@@ -22,10 +28,4 @@ class UserFlagsBitField extends BitField {}
* @name UserFlagsBitField#bitfield * @name UserFlagsBitField#bitfield
*/ */
/**
* Numeric user flags.
* @type {UserFlags}
*/
UserFlagsBitField.Flags = UserFlags;
module.exports = UserFlagsBitField; module.exports = UserFlagsBitField;

View File

@@ -774,8 +774,8 @@ export class ClientUser extends User {
export class Options extends null { export class Options extends null {
private constructor(); private constructor();
public static defaultMakeCacheSettings: CacheWithLimitsOptions; public static get DefaultMakeCacheSettings(): CacheWithLimitsOptions;
public static defaultSweeperSettings: SweeperOptions; public static get DefaultSweeperSettings(): SweeperOptions;
public static createDefault(): ClientOptions; public static createDefault(): ClientOptions;
public static cacheWithLimits(settings?: CacheWithLimitsOptions): CacheFactory; public static cacheWithLimits(settings?: CacheWithLimitsOptions): CacheFactory;
public static cacheEverything(): CacheFactory; public static cacheEverything(): CacheFactory;
@@ -1356,7 +1356,7 @@ export class GuildTemplate extends Base {
public delete(): Promise<GuildTemplate>; public delete(): Promise<GuildTemplate>;
public edit(options?: EditGuildTemplateOptions): Promise<GuildTemplate>; public edit(options?: EditGuildTemplateOptions): Promise<GuildTemplate>;
public sync(): Promise<GuildTemplate>; public sync(): Promise<GuildTemplate>;
public static GUILD_TEMPLATES_PATTERN: RegExp; public static GuildTemplatesPattern: RegExp;
} }
export class GuildPreviewEmoji extends BaseGuildEmoji { export class GuildPreviewEmoji extends BaseGuildEmoji {
@@ -1525,7 +1525,7 @@ export class Invite extends Base {
public delete(reason?: string): Promise<Invite>; public delete(reason?: string): Promise<Invite>;
public toJSON(): unknown; public toJSON(): unknown;
public toString(): string; public toString(): string;
public static INVITES_PATTERN: RegExp; public static InvitesPattern: RegExp;
/** @deprecated */ /** @deprecated */
public stageInstance: InviteStageInstance | null; public stageInstance: InviteStageInstance | null;
public guildScheduledEvent: GuildScheduledEvent | null; public guildScheduledEvent: GuildScheduledEvent | null;
@@ -1773,10 +1773,10 @@ export class MessageMentions {
public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>; public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>;
public toJSON(): unknown; public toJSON(): unknown;
public static CHANNELS_PATTERN: RegExp; public static ChannelsPattern: RegExp;
public static EVERYONE_PATTERN: RegExp; public static EveryonePattern: RegExp;
public static ROLES_PATTERN: RegExp; public static RolesPattern: RegExp;
public static USERS_PATTERN: RegExp; public static UsersPattern: RegExp;
} }
export class MessagePayload { export class MessagePayload {