From a59b29d7e5a0819edd32a981862a91f2b488f19e Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 12 Apr 2022 10:40:30 +0100 Subject: [PATCH 1/4] feat(attachments-type): Attachments refactor Co-authored-by: bsian03 Co-authored-by: TTtie Co-authored-by: Donovan Daniels --- esm.mjs | 1 + index.d.ts | 23 +++++++-- index.js | 1 + lib/Constants.js | 22 ++++----- lib/structures/Attachment.js | 59 +++++++++++++++++++++++ lib/structures/AutocompleteInteraction.js | 2 +- lib/structures/CommandInteraction.js | 21 +++++--- lib/structures/Message.js | 44 +++++++++++------ 8 files changed, 138 insertions(+), 35 deletions(-) create mode 100644 lib/structures/Attachment.js diff --git a/esm.mjs b/esm.mjs index dcbdbdd5d..8aac8db87 100644 --- a/esm.mjs +++ b/esm.mjs @@ -6,6 +6,7 @@ export default function (token, options) { export const { ApplicationCommand, + Attachment, AutocompleteInteraction, Base, Bucket, diff --git a/index.d.ts b/index.d.ts index b53574110..64db7c71c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -21,6 +21,7 @@ declare namespace Eris { // Application Commands type ApplicationCommandOptions = ApplicationCommandOptionsSubCommand | ApplicationCommandOptionsSubCommandGroup | ApplicationCommandOptionsWithValue; + type ApplicationCommandOptionsAttachment = ApplicationCommandOption; type ApplicationCommandOptionsBoolean = ApplicationCommandOption; type ApplicationCommandOptionsChannel = ApplicationCommandOption; type ApplicationCommandOptionsInteger = ApplicationCommandOptionsIntegerWithAutocomplete | ApplicationCommandOptionsIntegerWithoutAutocomplete | ApplicationCommandOptionsIntegerWithMinMax; @@ -37,7 +38,7 @@ declare namespace Eris { type ApplicationCommandOptionsStringWithAutocomplete = Omit, "choices"> & AutocompleteEnabled; type ApplicationCommandOptionsStringWithoutAutocomplete = Omit, "autocomplete"> & AutocompleteDisabled; type ApplicationCommandOptionsUser = ApplicationCommandOption; - type ApplicationCommandOptionsWithValue = ApplicationCommandOptionsString | ApplicationCommandOptionsInteger | ApplicationCommandOptionsBoolean | ApplicationCommandOptionsUser | ApplicationCommandOptionsChannel | ApplicationCommandOptionsRole | ApplicationCommandOptionsMentionable | ApplicationCommandOptionsNumber; + type ApplicationCommandOptionsWithValue = ApplicationCommandOptionsString | ApplicationCommandOptionsInteger | ApplicationCommandOptionsBoolean | ApplicationCommandOptionsUser | ApplicationCommandOptionsChannel | ApplicationCommandOptionsRole | ApplicationCommandOptionsMentionable | ApplicationCommandOptionsNumber | ApplicationCommandOptionsAttachment; type ApplicationCommandPermissionTypes = Constants["ApplicationCommandPermissionTypes"][keyof Constants["ApplicationCommandPermissionTypes"]]; type ApplicationCommandTypes = Constants["ApplicationCommandTypes"][keyof Constants["ApplicationCommandTypes"]]; type ModalSubmitInteractionDataComponent = ModalSubmitInteractionDataTextInputComponent; @@ -136,6 +137,7 @@ declare namespace Eris { type InteractionContent = Pick; type InteractionContentEdit = Pick; type InteractionDataOptions = InteractionDataOptionsSubCommand | InteractionDataOptionsSubCommandGroup | InteractionDataOptionsWithValue; + type InteractionDataOptionsAttachment = InteractionDataOptionWithValue; type InteractionDataOptionsBoolean = InteractionDataOptionWithValue; type InteractionDataOptionsChannel = InteractionDataOptionWithValue; type InteractionDataOptionsInteger = InteractionDataOptionWithValue; @@ -144,7 +146,7 @@ declare namespace Eris { type InteractionDataOptionsRole = InteractionDataOptionWithValue; type InteractionDataOptionsString = InteractionDataOptionWithValue; type InteractionDataOptionsUser = InteractionDataOptionWithValue; - type InteractionDataOptionsWithValue = InteractionDataOptionsString | InteractionDataOptionsInteger | InteractionDataOptionsBoolean | InteractionDataOptionsUser | InteractionDataOptionsChannel | InteractionDataOptionsRole | InteractionDataOptionsMentionable | InteractionDataOptionsNumber; + type InteractionDataOptionsWithValue = InteractionDataOptionsString | InteractionDataOptionsInteger | InteractionDataOptionsBoolean | InteractionDataOptionsUser | InteractionDataOptionsChannel | InteractionDataOptionsRole | InteractionDataOptionsMentionable | InteractionDataOptionsNumber | InteractionDataOptionsAttachment; type InteractionResponseTypes = Constants["InteractionResponseTypes"][keyof Constants["InteractionResponseTypes"]]; type InteractionTypes = Constants["InteractionTypes"][keyof Constants["InteractionTypes"]]; type LocaleStrings = Constants["Locales"][keyof Constants["Locales"]]; @@ -1517,6 +1519,7 @@ declare namespace Eris { } interface Attachment extends PartialAttachment { content_type?: string; + description?: string; duration_secs?: number; ephemeral?: boolean; filename: string; @@ -2042,6 +2045,20 @@ declare namespace Eris { edit(options: ApplicationCommandEditOptions): Promise>; } + export class Attachment extends Base { + contentType?: string; + description?: string; + ephemeral?: boolean; + filename: string; + height?: number; + id: string; + proxyURL: string; + size: number; + url: string; + width?: number; + constructor(data: BaseData); + } + class Base implements SimpleJSON { createdAt: number; id: string; @@ -3072,7 +3089,7 @@ declare namespace Eris { activity?: MessageActivity; application?: MessageApplication; applicationID?: string; - attachments: Attachment[]; + attachments: Collection; author: User; channel: T; channelMentions: string[]; diff --git a/index.js b/index.js index 53b07eefc..51bb9d235 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ function Eris(token, options) { } Eris.ApplicationCommand = require("./lib/structures/ApplicationCommand"); +Eris.Attachment = require("./lib/structures/Attachment"); Eris.AutocompleteInteraction = require("./lib/structures/AutocompleteInteraction"); Eris.Base = require("./lib/structures/Base"); Eris.Bucket = require("./lib/util/Bucket"); diff --git a/lib/Constants.js b/lib/Constants.js index 592598890..039313975 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -25,17 +25,17 @@ module.exports.ActivityTypes = { }; module.exports.ApplicationCommandOptionTypes = { - SUB_COMMAND: 1, - SUB_COMMAND_GROUP: 2, - STRING: 3, - INTEGER: 4, - BOOLEAN: 5, - USER: 6, - CHANNEL: 7, - ROLE: 8, - MENTIONABLE: 9, - NUMBER: 10, - ATTACHMENT: 11, + SUB_COMMAND: 1, + SUB_COMMAND_GROUP: 2, + STRING: 3, + INTEGER: 4, + BOOLEAN: 5, + USER: 6, + CHANNEL: 7, + ROLE: 8, + MENTIONABLE: 9, + NUMBER: 10, + ATTACHMENT: 11, }; module.exports.ApplicationCommandPermissionTypes = { diff --git a/lib/structures/Attachment.js b/lib/structures/Attachment.js new file mode 100644 index 000000000..e69d826b4 --- /dev/null +++ b/lib/structures/Attachment.js @@ -0,0 +1,59 @@ +"use strict"; + +const Base = require("./Base"); + +/** + * Represents an attachment + * @prop {String?} contentType The content type of the attachment + * @prop {String?} description The description of the attachment + * @prop {Boolean?} ephemeral Whether the attachment is ephemeral + * @prop {String} filename The filename of the attachment + * @prop {Number?} height The height of the attachment + * @prop {String} id The attachment ID + * @prop {String} proxyURL The proxy URL of the attachment + * @prop {Number} size The size of the attachment + * @prop {String} url The URL of the attachment + * @prop {Number?} width The width of the attachment + */ +class Attachment extends Base { + constructor(data) { + super(data.id); + + this.filename = data.filename; + this.size = data.size; + this.url = data.url; + this.proxyURL = data.proxy_url; + if(data.description !== undefined) { + this.description = data.description; + } + if(data.content_type !== undefined) { + this.contentType = data.content_type; + } + if(data.height !== undefined) { + this.height = data.height; + } + if(data.width !== undefined) { + this.width = data.width; + } + if(data.ephemeral !== undefined) { + this.ephemeral = data.ephemeral; + } + } + + toJSON(props = []) { + return super.toJSON([ + "filename", + "description", + "contentType", + "size", + "url", + "proxyUrl", + "height", + "width", + "ephemeral", + ...props + ]); + } +} + +module.exports = Attachment; diff --git a/lib/structures/AutocompleteInteraction.js b/lib/structures/AutocompleteInteraction.js index ae51feb8e..8e2a16527 100644 --- a/lib/structures/AutocompleteInteraction.js +++ b/lib/structures/AutocompleteInteraction.js @@ -16,7 +16,7 @@ const { InteractionResponseTypes } = require("../Constants"); * @prop {Boolean?} data.options[].focused Whether or not the option is focused * @prop {String} data.options[].name The name of the Application Command option * @prop {Array?} data.options[].options The run Application Command options (Mutually exclusive with value) - * @prop {Number} data.options[].type Command option type, 1-10 + * @prop {Number} data.options[].type Command option type, 1-11 * @prop {(String | Number | Boolean)?} data.options[].value The value of the run Application Command (Mutually exclusive with options) * @prop {String?} data.target_id The ID the of user or message targetted by a context menu command * @prop {Number} data.type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types) diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index e836588ae..ca7244235 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -6,6 +6,7 @@ const User = require("./User"); const Role = require("./Role"); const Channel = require("./Channel"); const Message = require("./Message"); +const Attachment = require("./Attachment"); const Collection = require("../util/Collection"); const Permission = require("./Permission"); @@ -22,7 +23,7 @@ const { InteractionResponseTypes } = require("../Constants"); * @prop {Array?} data.options The run Application Command options * @prop {String} data.options[].name The name of the Application Command option * @prop {Array?} data.options[].options The run Application Command options (Mutually exclusive with value) - * @prop {Number} data.options[].type Command option type, 1-10 + * @prop {Number} data.options[].type Command option type, 1-11 * @prop {(String | Number | Boolean)?} data.options[].value The value of the run Application Command (Mutually exclusive with options) * @prop {String?} data.target_id The ID the of user or message targetted by a context menu command * @prop {Number} data.type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types) @@ -89,11 +90,19 @@ class CommandInteraction extends Interaction { if (data.data.resolved.messages !== undefined) { const messagemap = new Collection(Message); Object.entries(data.data.resolved.messages).forEach(([id, message]) => { - messagemap.set(id, new Message(message, this._client)); - }); - this.data.resolved.messages = messagemap; - } - } + messagemap.set(id, new Message(message, this._client)); + }); + this.data.resolved.messages = messagemap; + } + //Attachments + if(data.data.resolved.attachments !== undefined) { + const attachmentsmap = new Collection(Attachment); + Object.entries(data.data.resolved.attachments).forEach(([id, attachment]) => { + attachmentsmap.set(id, new Attachment(attachment)); + }); + this.data.resolved.attachments = attachmentsmap; + } + } if (data.guild_id !== undefined) { this.guildID = data.guild_id; diff --git a/lib/structures/Message.js b/lib/structures/Message.js index e8bf3e303..ee4cd3383 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -4,6 +4,8 @@ const Base = require("./Base"); const Endpoints = require("../rest/Endpoints"); const { MessageFlags } = require("../Constants"); const User = require("./User"); +const Attachment = require("./Attachment"); +const Collection = require("../util/Collection"); /** * Represents a message @@ -61,9 +63,10 @@ class Message extends Base { super(data.id); this._client = client; this.type = data.type || 0; - this.timestamp = Date.parse(data.timestamp); - this.channel = this._client.getChannel(data.channel_id) || { - id: data.channel_id, + this.attachments = new Collection(Attachment); + this.timestamp = Date.parse(data.timestamp); + this.channel = this._client.getChannel(data.channel_id) || { + id: data.channel_id, }; this.content = ""; this.reactions = {}; @@ -166,6 +169,12 @@ class Message extends Base { this.member = null; } + if(data.attachments) { + for(const attachment of data.attachments) { + this.attachments.add(attachment, this); + } + } + this.update(data, client); } @@ -191,17 +200,24 @@ class Message extends Base { this.poll.expiry = Date.parse(data.poll.expiry); } } - if (data.pinned !== undefined) { - this.pinned = !!data.pinned; - } - if (data.edited_timestamp != undefined) { - this.editedTimestamp = Date.parse(data.edited_timestamp); - } - if (data.tts !== undefined) { - this.tts = data.tts; - } - if (data.attachments !== undefined) { - this.attachments = data.attachments; + if(data.pinned !== undefined) { + this.pinned = !!data.pinned; + } + if(data.edited_timestamp != undefined) { + this.editedTimestamp = Date.parse(data.edited_timestamp); + } + if(data.tts !== undefined) { + this.tts = data.tts; + } + if(data.attachments) { + for(const id of this.attachments.keys()) { + if(!data.attachments.some((attachment) => attachment.id === id)) { + this.attachments.delete(id); + } + } + for(const attachment of data.attachments) { + this.attachments.update(attachment, this); + } } if (data.embeds !== undefined) { this.embeds = data.embeds; From bc7918821754a7f7d012fc09d5ef7abc8bf3b187 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 20 Oct 2024 01:27:17 +0100 Subject: [PATCH 2/4] feat(attachments-type): Re-lint all PR files --- index.d.ts | 15 ------ lib/Constants.d.ts | 1 + lib/Constants.js | 22 ++++----- lib/structures/Attachment.js | 70 ++++++++++++++-------------- lib/structures/CommandInteraction.js | 54 ++++++++++----------- lib/structures/Message.js | 50 ++++++++++---------- 6 files changed, 99 insertions(+), 113 deletions(-) diff --git a/index.d.ts b/index.d.ts index 64db7c71c..a7b9575fb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1517,21 +1517,6 @@ declare namespace Eris { roles?: boolean | string[]; users?: boolean | string[]; } - interface Attachment extends PartialAttachment { - content_type?: string; - description?: string; - duration_secs?: number; - ephemeral?: boolean; - filename: string; - flags?: number; - height?: number; - id: string; - proxy_url: string; - size: number; - url: string; - waveform?: string; - width?: number; - } interface ButtonBase { disabled?: boolean; emoji?: Partial; diff --git a/lib/Constants.d.ts b/lib/Constants.d.ts index f6fe83994..ca2356e9f 100644 --- a/lib/Constants.d.ts +++ b/lib/Constants.d.ts @@ -31,6 +31,7 @@ export default interface Constants { ROLE: 8; MENTIONABLE: 9; NUMBER: 10; + ATTACHMENT: 11; }; ApplicationCommandPermissionTypes: { ROLE: 1; diff --git a/lib/Constants.js b/lib/Constants.js index 039313975..592598890 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -25,17 +25,17 @@ module.exports.ActivityTypes = { }; module.exports.ApplicationCommandOptionTypes = { - SUB_COMMAND: 1, - SUB_COMMAND_GROUP: 2, - STRING: 3, - INTEGER: 4, - BOOLEAN: 5, - USER: 6, - CHANNEL: 7, - ROLE: 8, - MENTIONABLE: 9, - NUMBER: 10, - ATTACHMENT: 11, + SUB_COMMAND: 1, + SUB_COMMAND_GROUP: 2, + STRING: 3, + INTEGER: 4, + BOOLEAN: 5, + USER: 6, + CHANNEL: 7, + ROLE: 8, + MENTIONABLE: 9, + NUMBER: 10, + ATTACHMENT: 11, }; module.exports.ApplicationCommandPermissionTypes = { diff --git a/lib/structures/Attachment.js b/lib/structures/Attachment.js index e69d826b4..4746ddceb 100644 --- a/lib/structures/Attachment.js +++ b/lib/structures/Attachment.js @@ -16,44 +16,44 @@ const Base = require("./Base"); * @prop {Number?} width The width of the attachment */ class Attachment extends Base { - constructor(data) { - super(data.id); + constructor(data) { + super(data.id); - this.filename = data.filename; - this.size = data.size; - this.url = data.url; - this.proxyURL = data.proxy_url; - if(data.description !== undefined) { - this.description = data.description; - } - if(data.content_type !== undefined) { - this.contentType = data.content_type; - } - if(data.height !== undefined) { - this.height = data.height; - } - if(data.width !== undefined) { - this.width = data.width; - } - if(data.ephemeral !== undefined) { - this.ephemeral = data.ephemeral; - } + this.filename = data.filename; + this.size = data.size; + this.url = data.url; + this.proxyURL = data.proxy_url; + if (data.description !== undefined) { + this.description = data.description; } - - toJSON(props = []) { - return super.toJSON([ - "filename", - "description", - "contentType", - "size", - "url", - "proxyUrl", - "height", - "width", - "ephemeral", - ...props - ]); + if (data.content_type !== undefined) { + this.contentType = data.content_type; + } + if (data.height !== undefined) { + this.height = data.height; + } + if (data.width !== undefined) { + this.width = data.width; } + if (data.ephemeral !== undefined) { + this.ephemeral = data.ephemeral; + } + } + + toJSON(props = []) { + return super.toJSON([ + "filename", + "description", + "contentType", + "size", + "url", + "proxyURL", + "height", + "width", + "ephemeral", + ...props, + ]); + } } module.exports = Attachment; diff --git a/lib/structures/CommandInteraction.js b/lib/structures/CommandInteraction.js index ca7244235..610b6d1e8 100644 --- a/lib/structures/CommandInteraction.js +++ b/lib/structures/CommandInteraction.js @@ -49,60 +49,60 @@ class CommandInteraction extends Interaction { if (data.data.resolved !== undefined) { // Users if (data.data.resolved.users !== undefined) { - const usermap = new Collection(User); + const userMap = new Collection(User); Object.entries(data.data.resolved.users).forEach(([id, user]) => { - usermap.set(id, this._client.users.update(user, client)); + userMap.set(id, this._client.users.update(user, client)); }); - this.data.resolved.users = usermap; + this.data.resolved.users = userMap; } // Members if (data.data.resolved.members !== undefined) { - const membermap = new Collection(Member); + const memberMap = new Collection(Member); Object.entries(data.data.resolved.members).forEach(([id, member]) => { member.id = id; member.user = { id }; if (this.channel.guild) { - membermap.set(id, this.channel.guild.members.update(member, this.channel.guild)); + memberMap.set(id, this.channel.guild.members.update(member, this.channel.guild)); } else { const guild = this._client.guilds.get(data.guild_id); - membermap.set(id, guild.members.update(member, guild)); + memberMap.set(id, guild.members.update(member, guild)); } }); - this.data.resolved.members = membermap; + this.data.resolved.members = memberMap; } // Roles if (data.data.resolved.roles !== undefined) { - const rolemap = new Collection(Role); + const roleMap = new Collection(Role); Object.entries(data.data.resolved.roles).forEach(([id, role]) => { - rolemap.set(id, new Role(role, this._client)); + roleMap.set(id, new Role(role, this._client)); }); - this.data.resolved.roles = rolemap; + this.data.resolved.roles = roleMap; } // Channels if (data.data.resolved.channels !== undefined) { - const channelmap = new Collection(Channel); + const channelMap = new Collection(Channel); Object.entries(data.data.resolved.channels).forEach(([id, channel]) => { - channelmap.set(id, new Channel(channel, this._client)); + channelMap.set(id, new Channel(channel, this._client)); }); - this.data.resolved.channels = channelmap; + this.data.resolved.channels = channelMap; } // Messages if (data.data.resolved.messages !== undefined) { - const messagemap = new Collection(Message); + const messageMap = new Collection(Message); Object.entries(data.data.resolved.messages).forEach(([id, message]) => { - messagemap.set(id, new Message(message, this._client)); - }); - this.data.resolved.messages = messagemap; - } - //Attachments - if(data.data.resolved.attachments !== undefined) { - const attachmentsmap = new Collection(Attachment); - Object.entries(data.data.resolved.attachments).forEach(([id, attachment]) => { - attachmentsmap.set(id, new Attachment(attachment)); - }); - this.data.resolved.attachments = attachmentsmap; - } - } + messageMap.set(id, new Message(message, this._client)); + }); + this.data.resolved.messages = messageMap; + } + // Attachments + if (data.data.resolved.attachments !== undefined) { + const attachmentMap = new Collection(Attachment); + Object.entries(data.data.resolved.attachments).forEach(([id, attachment]) => { + attachmentMap.set(id, new Attachment(attachment)); + }); + this.data.resolved.attachments = attachmentMap; + } + } if (data.guild_id !== undefined) { this.guildID = data.guild_id; diff --git a/lib/structures/Message.js b/lib/structures/Message.js index ee4cd3383..a073d16dc 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -64,9 +64,9 @@ class Message extends Base { this._client = client; this.type = data.type || 0; this.attachments = new Collection(Attachment); - this.timestamp = Date.parse(data.timestamp); - this.channel = this._client.getChannel(data.channel_id) || { - id: data.channel_id, + this.timestamp = Date.parse(data.timestamp); + this.channel = this._client.getChannel(data.channel_id) || { + id: data.channel_id, }; this.content = ""; this.reactions = {}; @@ -169,11 +169,11 @@ class Message extends Base { this.member = null; } - if(data.attachments) { - for(const attachment of data.attachments) { - this.attachments.add(attachment, this); - } - } + if (data.attachments) { + for (const attachment of data.attachments) { + this.attachments.add(attachment, this); + } + } this.update(data, client); } @@ -200,24 +200,24 @@ class Message extends Base { this.poll.expiry = Date.parse(data.poll.expiry); } } - if(data.pinned !== undefined) { - this.pinned = !!data.pinned; - } - if(data.edited_timestamp != undefined) { - this.editedTimestamp = Date.parse(data.edited_timestamp); - } - if(data.tts !== undefined) { - this.tts = data.tts; + if (data.pinned !== undefined) { + this.pinned = !!data.pinned; + } + if (data.edited_timestamp !== undefined) { + this.editedTimestamp = Date.parse(data.edited_timestamp); + } + if (data.tts !== undefined) { + this.tts = data.tts; + } + if (data.attachments) { + for (const id of this.attachments.keys()) { + if (!data.attachments.some((attachment) => attachment.id === id)) { + this.attachments.delete(id); } - if(data.attachments) { - for(const id of this.attachments.keys()) { - if(!data.attachments.some((attachment) => attachment.id === id)) { - this.attachments.delete(id); - } - } - for(const attachment of data.attachments) { - this.attachments.update(attachment, this); - } + } + for (const attachment of data.attachments) { + this.attachments.update(attachment, this); + } } if (data.embeds !== undefined) { this.embeds = data.embeds; From b52ade6d4ebecf7bd408f86668686dc041b18090 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 20 Oct 2024 02:07:51 +0100 Subject: [PATCH 3/4] feat(attachments-type): Add new attachment fields --- index.d.ts | 4 +++ lib/structures/Attachment.js | 56 ++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/index.d.ts b/index.d.ts index a7b9575fb..62d2f4220 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2033,13 +2033,17 @@ declare namespace Eris { export class Attachment extends Base { contentType?: string; description?: string; + durationSeconds?: number; ephemeral?: boolean; filename: string; + flags?: number; height?: number; id: string; proxyURL: string; size: number; + title?: string; url: string; + waveform?: string; width?: number; constructor(data: BaseData); } diff --git a/lib/structures/Attachment.js b/lib/structures/Attachment.js index 4746ddceb..e6e59c88f 100644 --- a/lib/structures/Attachment.js +++ b/lib/structures/Attachment.js @@ -4,53 +4,73 @@ const Base = require("./Base"); /** * Represents an attachment - * @prop {String?} contentType The content type of the attachment - * @prop {String?} description The description of the attachment + * @prop {String?} contentType The attachment's media type + * @prop {String?} description The description for the file (max 1024 characters) + * @prop {Number?} durationSeconds The duration of the audio file (currently for voice messages) * @prop {Boolean?} ephemeral Whether the attachment is ephemeral - * @prop {String} filename The filename of the attachment - * @prop {Number?} height The height of the attachment + * @prop {String} filename The name of file attached + * @prop {Number?} flags The attachment flags combined as a bitfield + * @prop {Number?} height The height of file (if image) * @prop {String} id The attachment ID * @prop {String} proxyURL The proxy URL of the attachment - * @prop {Number} size The size of the attachment - * @prop {String} url The URL of the attachment - * @prop {Number?} width The width of the attachment + * @prop {Number} size The size of the file in bytes + * @prop {String?} title The title of the file + * @prop {String} url The source URL of the file + * @prop {String?} waveform The base64 encoded bytearray representing a sampled waveform (currently for voice messages) + * @prop {Number?} width The width of file (if image) */ class Attachment extends Base { constructor(data) { super(data.id); this.filename = data.filename; + this.proxyURL = data.proxy_url; this.size = data.size; this.url = data.url; - this.proxyURL = data.proxy_url; + + if (data.content_type !== undefined) { + this.contentType = data.content_type; + } if (data.description !== undefined) { this.description = data.description; } - if (data.content_type !== undefined) { - this.contentType = data.content_type; + if (data.duration_secs !== undefined) { + this.durationSeconds = data.duration_secs; + } + if (data.ephemeral !== undefined) { + this.ephemeral = data.ephemeral; + } + if (data.flags !== undefined) { + this.flags = data.flags; } if (data.height !== undefined) { this.height = data.height; } + if (data.title !== undefined) { + this.title = data.title; + } + if (data.waveform !== undefined) { + this.waveform = data.waveform; + } if (data.width !== undefined) { this.width = data.width; } - if (data.ephemeral !== undefined) { - this.ephemeral = data.ephemeral; - } } toJSON(props = []) { return super.toJSON([ - "filename", - "description", "contentType", + "description", + "durationSeconds", + "ephemeral", + "filename", + "flags", + "height", + "proxyURL", "size", "url", - "proxyURL", - "height", + "waveform", "width", - "ephemeral", ...props, ]); } From 4d23f592cc0a23a011a83a6a1f2378cfb06af9a4 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 20 Oct 2024 02:09:14 +0100 Subject: [PATCH 4/4] feat(attachments-type): Title was missed in toJSON call --- lib/structures/Attachment.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/structures/Attachment.js b/lib/structures/Attachment.js index e6e59c88f..a5b8b297a 100644 --- a/lib/structures/Attachment.js +++ b/lib/structures/Attachment.js @@ -68,6 +68,7 @@ class Attachment extends Base { "height", "proxyURL", "size", + "title", "url", "waveform", "width",