|
3 | 3 | const Util = require('../util/Util');
|
4 | 4 |
|
5 | 5 | /**
|
6 |
| - * Represents an attachment. |
| 6 | + * @typedef {Object} AttachmentPayload |
| 7 | + * @property {?string} name The name of the attachment |
| 8 | + * @property {Stream|BufferResolvable} attachment The attachment in this payload |
| 9 | + * @property {?string} description The description of the attachment |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * Represents an attachment |
7 | 14 | */
|
8 | 15 | class Attachment {
|
9 | 16 | /**
|
10 |
| - * @param {BufferResolvable|Stream} attachment The file |
11 |
| - * @param {string} [name=null] The name of the file, if any |
12 |
| - * @param {APIAttachment} [data] Extra data |
| 17 | + * @param {APIAttachment} data Attachment data |
| 18 | + * @private |
13 | 19 | */
|
14 |
| - constructor(attachment, name = null, data) { |
15 |
| - this.attachment = attachment; |
| 20 | + constructor({ url, filename, ...data }) { |
| 21 | + this.attachment = url; |
16 | 22 | /**
|
17 | 23 | * The name of this attachment
|
18 |
| - * @type {?string} |
| 24 | + * @type {string} |
19 | 25 | */
|
20 |
| - this.name = name; |
| 26 | + this.name = filename; |
21 | 27 | if (data) this._patch(data);
|
22 | 28 | }
|
23 | 29 |
|
24 |
| - /** |
25 |
| - * Sets the description of this attachment. |
26 |
| - * @param {string} description The description of the file |
27 |
| - * @returns {Attachment} This attachment |
28 |
| - */ |
29 |
| - setDescription(description) { |
30 |
| - this.description = description; |
31 |
| - return this; |
32 |
| - } |
33 |
| - |
34 |
| - /** |
35 |
| - * Sets the file of this attachment. |
36 |
| - * @param {BufferResolvable|Stream} attachment The file |
37 |
| - * @param {string} [name=null] The name of the file, if any |
38 |
| - * @returns {Attachment} This attachment |
39 |
| - */ |
40 |
| - setFile(attachment, name = null) { |
41 |
| - this.attachment = attachment; |
42 |
| - this.name = name; |
43 |
| - return this; |
44 |
| - } |
45 |
| - |
46 |
| - /** |
47 |
| - * Sets the name of this attachment. |
48 |
| - * @param {string} name The name of the file |
49 |
| - * @returns {Attachment} This attachment |
50 |
| - */ |
51 |
| - setName(name) { |
52 |
| - this.name = name; |
53 |
| - return this; |
54 |
| - } |
55 |
| - |
56 |
| - /** |
57 |
| - * Sets whether this attachment is a spoiler |
58 |
| - * @param {boolean} [spoiler=true] Whether the attachment should be marked as a spoiler |
59 |
| - * @returns {Attachment} This attachment |
60 |
| - */ |
61 |
| - setSpoiler(spoiler = true) { |
62 |
| - if (spoiler === this.spoiler) return this; |
63 |
| - |
64 |
| - if (!spoiler) { |
65 |
| - while (this.spoiler) { |
66 |
| - this.name = this.name.slice('SPOILER_'.length); |
67 |
| - } |
68 |
| - return this; |
69 |
| - } |
70 |
| - this.name = `SPOILER_${this.name}`; |
71 |
| - return this; |
72 |
| - } |
73 |
| - |
74 | 30 | _patch(data) {
|
75 | 31 | /**
|
76 | 32 | * The attachment's id
|
@@ -164,8 +120,3 @@ class Attachment {
|
164 | 120 | }
|
165 | 121 |
|
166 | 122 | module.exports = Attachment;
|
167 |
| - |
168 |
| -/** |
169 |
| - * @external APIAttachment |
170 |
| - * @see {@link https://discord.com/developers/docs/resources/channel#attachment-object} |
171 |
| - */ |
0 commit comments