Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Attachment): add flags #9686

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 11 additions & 0 deletions packages/discord.js/src/structures/Attachment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const AttachmentFlagsBitField = require('../util/AttachmentFlagsBitField.js');
const { basename, flatten } = require('../util/Util');

/**
Expand Down Expand Up @@ -121,6 +122,16 @@ class Attachment {
} else {
this.waveform ??= null;
}

if ('flags' in data) {
/**
* The flags of this attachment
* @type {Readonly<AttachmentFlagsBitField>}
*/
this.flags = new AttachmentFlagsBitField(data.flags).freeze();
} else {
this.flags ??= new AttachmentFlagsBitField().freeze();
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
26 changes: 26 additions & 0 deletions packages/discord.js/src/util/AttachmentFlagsBitField.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ import {
APIGuildOnboardingPrompt,
APIGuildOnboardingPromptOption,
GuildOnboardingPromptType,
AttachmentFlags,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -2070,6 +2071,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;
Expand All @@ -2082,6 +2084,13 @@ export class Attachment {
public toJSON(): unknown;
}

export type AttachmentFlagsString = keyof typeof AttachmentFlags;

export class AttachmentFlagsBitField extends BitField<AttachmentFlagsString> {
public static Flags: Record<AttachmentFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<AttachmentFlagsString, number>): number;
}

export class MessageCollector extends Collector<Snowflake, Message, [Collection<Snowflake, Message>]> {
public constructor(channel: TextBasedChannel, options?: MessageCollectorOptions);
private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;
Expand Down