From 227fa712d2223035fe84db6b109bf0dfb88f588f Mon Sep 17 00:00:00 2001 From: Almeida Date: Thu, 6 Jul 2023 01:57:46 +0100 Subject: [PATCH 1/3] feat(Attachment): add `flags` --- packages/discord.js/src/index.js | 1 + .../discord.js/src/structures/Attachment.js | 11 ++++++++ packages/discord.js/src/util/APITypes.js | 5 ++++ .../src/util/AttachmentFlagsBitField.js | 26 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 9 +++++++ 5 files changed, 52 insertions(+) create mode 100644 packages/discord.js/src/util/AttachmentFlagsBitField.js diff --git a/packages/discord.js/src/index.js b/packages/discord.js/src/index.js index 3c0dcd96319b..a7137270aa17 100644 --- a/packages/discord.js/src/index.js +++ b/packages/discord.js/src/index.js @@ -19,6 +19,7 @@ exports.DiscordjsErrorCodes = require('./errors/ErrorCodes'); // Utilities exports.ActivityFlagsBitField = require('./util/ActivityFlagsBitField'); exports.ApplicationFlagsBitField = require('./util/ApplicationFlagsBitField'); +exports.AttachmentFlagsBitField = require('./util/AttachmentFlagsBitField'); exports.BaseManager = require('./managers/BaseManager'); exports.BitField = require('./util/BitField'); exports.ChannelFlagsBitField = require('./util/ChannelFlagsBitField'); diff --git a/packages/discord.js/src/structures/Attachment.js b/packages/discord.js/src/structures/Attachment.js index 086d7a870731..2576ff59cdb1 100644 --- a/packages/discord.js/src/structures/Attachment.js +++ b/packages/discord.js/src/structures/Attachment.js @@ -1,5 +1,6 @@ 'use strict'; +const AttachmentFlagsBitField = require('../util/AttachmentFlagsBitField.js'); const { basename, flatten } = require('../util/Util'); /** @@ -121,6 +122,16 @@ class Attachment { } else { this.waveform ??= null; } + + if ('flags' in data) { + /** + * The flags of this attachment + * @type {Readonly} + */ + this.flags = new AttachmentFlagsBitField(data.flags).freeze(); + } else { + this.flags ??= new AttachmentFlagsBitField().freeze(); + } } /** diff --git a/packages/discord.js/src/util/APITypes.js b/packages/discord.js/src/util/APITypes.js index 11d468ada3a5..12c67b79ed2b 100644 --- a/packages/discord.js/src/util/APITypes.js +++ b/packages/discord.js/src/util/APITypes.js @@ -210,6 +210,11 @@ * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationRoleConnectionMetadataType} */ +/** + * @external AttachmentFlags + * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/AttachmentFlags} + */ + /** * @external AutoModerationActionType * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/AutoModerationActionType} diff --git a/packages/discord.js/src/util/AttachmentFlagsBitField.js b/packages/discord.js/src/util/AttachmentFlagsBitField.js new file mode 100644 index 000000000000..f7f2bd23d0d6 --- /dev/null +++ b/packages/discord.js/src/util/AttachmentFlagsBitField.js @@ -0,0 +1,26 @@ +'use strict'; + +const { AttachmentFlags } = require('discord-api-types/v10'); +const BitField = require('./BitField'); + +/** + * Data structure that makes it easy to interact with an {@link Attachment#flags} bitfield. + * @extends {BitField} + */ +class AttachmentFlagsBitField extends BitField { + /** + * Numeric attachment flags. + * @type {AttachmentFlags} + * @memberof AttachmentFlagsBitField + */ + static Flags = AttachmentFlags; +} + +/** + * @name AttachmentFlagsBitField + * @kind constructor + * @memberof AttachmentFlagsBitField + * @param {BitFieldResolvable} [bits=0] Bit(s) to read from + */ + +module.exports = AttachmentFlagsBitField; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index bd34b1d75c82..c53acddeffdc 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2065,6 +2065,7 @@ export class Attachment { public description: string | null; public duration: number | null; public ephemeral: boolean; + public flags: AttachmentFlagsBitField; public height: number | null; public id: Snowflake; public name: string; @@ -2077,6 +2078,14 @@ export class Attachment { public toJSON(): unknown; } +export type AttachmentFlagsString = any; +// export type AttachmentFlagsString = keyof typeof AttachmentFlags; + +export class AttachmentFlagsBitField extends BitField { + public static FLAGS: Record; + public static resolve(bit?: BitFieldResolvable): number; +} + export class MessageCollector extends Collector]> { public constructor(channel: TextBasedChannel, options?: MessageCollectorOptions); private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void; From ce3f66c7d6300b7faf548588a49d03e0bd61f4b9 Mon Sep 17 00:00:00 2001 From: Almeida Date: Wed, 19 Jul 2023 15:09:07 +0100 Subject: [PATCH 2/3] fix: import --- packages/discord.js/typings/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index c53acddeffdc..b8069bb3f519 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -161,6 +161,7 @@ import { APIGuildOnboardingPrompt, APIGuildOnboardingPromptOption, GuildOnboardingPromptType, + AttachmentFlags, } from 'discord-api-types/v10'; import { ChildProcess } from 'node:child_process'; import { EventEmitter } from 'node:events'; @@ -2078,8 +2079,7 @@ export class Attachment { public toJSON(): unknown; } -export type AttachmentFlagsString = any; -// export type AttachmentFlagsString = keyof typeof AttachmentFlags; +export type AttachmentFlagsString = keyof typeof AttachmentFlags; export class AttachmentFlagsBitField extends BitField { public static FLAGS: Record; From ea69bf89d01fb8026fad650b368c31a63d3a20aa Mon Sep 17 00:00:00 2001 From: Almeida Date: Wed, 19 Jul 2023 15:12:06 +0100 Subject: [PATCH 3/3] fix: flags casing Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index b8069bb3f519..122368d448c5 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2082,7 +2082,7 @@ export class Attachment { export type AttachmentFlagsString = keyof typeof AttachmentFlags; export class AttachmentFlagsBitField extends BitField { - public static FLAGS: Record; + public static Flags: Record; public static resolve(bit?: BitFieldResolvable): number; }