mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
refactor(Bitfield): use discord-api-types enums instead (#7313)
Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
@@ -3,7 +3,13 @@
|
||||
const { createComponent, Embed } = require('@discordjs/builders');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
const { InteractionType, ChannelType, MessageType } = require('discord-api-types/v9');
|
||||
const {
|
||||
InteractionType,
|
||||
ChannelType,
|
||||
MessageType,
|
||||
MessageFlags,
|
||||
PermissionFlagsBits,
|
||||
} = require('discord-api-types/v9');
|
||||
const Base = require('./Base');
|
||||
const ClientApplication = require('./ClientApplication');
|
||||
const InteractionCollector = require('./InteractionCollector');
|
||||
@@ -15,8 +21,8 @@ const { Sticker } = require('./Sticker');
|
||||
const { Error } = require('../errors');
|
||||
const ReactionManager = require('../managers/ReactionManager');
|
||||
const { NonSystemMessageTypes } = require('../util/Constants');
|
||||
const MessageFlags = require('../util/MessageFlags');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const MessageFlagsBitField = require('../util/MessageFlagsBitField');
|
||||
const PermissionsBitField = require('../util/PermissionsBitField');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
@@ -277,17 +283,17 @@ class Message extends Base {
|
||||
if ('flags' in data) {
|
||||
/**
|
||||
* Flags that are applied to the message
|
||||
* @type {Readonly<MessageFlags>}
|
||||
* @type {Readonly<MessageFlagsBitField>}
|
||||
*/
|
||||
this.flags = new MessageFlags(data.flags).freeze();
|
||||
this.flags = new MessageFlagsBitField(data.flags).freeze();
|
||||
} else {
|
||||
this.flags = new MessageFlags(this.flags).freeze();
|
||||
this.flags = new MessageFlagsBitField(this.flags).freeze();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference data sent in a message that contains ids identifying the referenced message.
|
||||
* This can be present in the following types of message:
|
||||
* * Crossposted messages (IS_CROSSPOST {@link MessageFlags.FLAGS message flag})
|
||||
* * Crossposted messages (`MessageFlags.Crossposted`)
|
||||
* * {@link MessageType.ChannelFollowAdd}
|
||||
* * {@link MessageType.ChannelPinnedMessage}
|
||||
* * {@link MessageType.Reply}
|
||||
@@ -403,7 +409,7 @@ class Message extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get hasThread() {
|
||||
return this.flags.has(MessageFlags.FLAGS.HAS_THREAD);
|
||||
return this.flags.has(MessageFlags.HasThread);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -571,11 +577,11 @@ class Message extends Base {
|
||||
const permissions = this.channel?.permissionsFor(this.client.user);
|
||||
if (!permissions) return false;
|
||||
// This flag allows deleting even if timed out
|
||||
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
|
||||
if (permissions.has(PermissionFlagsBits.Administrator, false)) return true;
|
||||
|
||||
return Boolean(
|
||||
this.author.id === this.client.user.id ||
|
||||
(permissions.has(Permissions.FLAGS.MANAGE_MESSAGES, false) &&
|
||||
(permissions.has(PermissionFlagsBits.ManageMessages, false) &&
|
||||
this.guild.me.communicationDisabledUntilTimestamp < Date.now()),
|
||||
);
|
||||
}
|
||||
@@ -591,7 +597,7 @@ class Message extends Base {
|
||||
!this.system &&
|
||||
(!this.guild ||
|
||||
(channel?.viewable &&
|
||||
channel?.permissionsFor(this.client.user)?.has(Permissions.FLAGS.MANAGE_MESSAGES, false))),
|
||||
channel?.permissionsFor(this.client.user)?.has(PermissionFlagsBits.ManageMessages, false))),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -615,12 +621,12 @@ class Message extends Base {
|
||||
*/
|
||||
get crosspostable() {
|
||||
const bitfield =
|
||||
Permissions.FLAGS.SEND_MESSAGES |
|
||||
(this.author.id === this.client.user.id ? Permissions.defaultBit : Permissions.FLAGS.MANAGE_MESSAGES);
|
||||
PermissionFlagsBits.SendMessages |
|
||||
(this.author.id === this.client.user.id ? PermissionsBitField.defaultBit : PermissionFlagsBits.ManageMessages);
|
||||
const { channel } = this;
|
||||
return Boolean(
|
||||
channel?.type === ChannelType.GuildNews &&
|
||||
!this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) &&
|
||||
!this.flags.has(MessageFlags.Crossposted) &&
|
||||
this.type === MessageType.Default &&
|
||||
channel.viewable &&
|
||||
channel.permissionsFor(this.client.user)?.has(bitfield, false),
|
||||
@@ -633,7 +639,8 @@ class Message extends Base {
|
||||
* @property {?string} [content] Content to be edited
|
||||
* @property {Embed[]|APIEmbed[]} [embeds] Embeds to be added/edited
|
||||
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
|
||||
* @property {MessageFlags} [flags] Which flags to set for the message. Only `SUPPRESS_EMBEDS` can be edited.
|
||||
* @property {MessageFlags} [flags] Which flags to set for the message.
|
||||
* Only `MessageFlags.SuppressEmbeds` can be edited.
|
||||
* @property {MessageAttachment[]} [attachments] An array of attachments to keep,
|
||||
* all attachments will be kept if omitted
|
||||
* @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] Files to add to the message
|
||||
@@ -844,12 +851,12 @@ class Message extends Base {
|
||||
* @returns {Promise<Message>}
|
||||
*/
|
||||
suppressEmbeds(suppress = true) {
|
||||
const flags = new MessageFlags(this.flags.bitfield);
|
||||
const flags = new MessageFlagsBitField(this.flags.bitfield);
|
||||
|
||||
if (suppress) {
|
||||
flags.add(MessageFlags.FLAGS.SUPPRESS_EMBEDS);
|
||||
flags.add(MessageFlags.SuppressEmbeds);
|
||||
} else {
|
||||
flags.remove(MessageFlags.FLAGS.SUPPRESS_EMBEDS);
|
||||
flags.remove(MessageFlags.SuppressEmbeds);
|
||||
}
|
||||
|
||||
return this.edit({ flags });
|
||||
|
||||
Reference in New Issue
Block a user