Skip to content

Commit

Permalink
feat(Attachment): add flags (#9686)
Browse files Browse the repository at this point in the history
* feat(Attachment): add `flags`

* fix: import

* fix: flags casing

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 10, 2023
1 parent 0de071d commit 692f0fc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
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

0 comments on commit 692f0fc

Please sign in to comment.