Skip to content

Commit

Permalink
feat(MessageAttachment): allow files to be marked as spoilers (#6509)
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
  • Loading branch information
J-Human and kyranet committed Aug 24, 2021
1 parent 5c27639 commit 96e26c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/structures/MessageAttachment.js
Expand Up @@ -43,6 +43,24 @@ class MessageAttachment {
return this;
}

/**
* Sets whether this attachment is a spoiler
* @param {boolean} [spoiler=true] Whether the attachment should be marked as a spoiler
* @returns {MessageAttachment} This attachment
*/
setSpoiler(spoiler = true) {
if (spoiler === this.spoiler) return this;

if (!spoiler) {
while (this.spoiler) {
this.name.slice('SPOILER_'.length);
}
return this;
}
this.name = `SPOILER_${this.name}`;
return this;
}

_patch(data) {
/**
* The attachment's id
Expand Down Expand Up @@ -93,7 +111,7 @@ class MessageAttachment {
* @readonly
*/
get spoiler() {
return Util.basename(this.url).startsWith('SPOILER_');
return Util.basename(this.url ?? this.name).startsWith('SPOILER_');
}

toJSON() {
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -1210,6 +1210,7 @@ export class MessageAttachment {
public width: number | null;
public setFile(attachment: BufferResolvable | Stream, name?: string): this;
public setName(name: string): this;
public setSpoiler(spoiler?: boolean): this;
public toJSON(): unknown;
}

Expand Down

0 comments on commit 96e26c4

Please sign in to comment.