From 4ca18647baf80b2d749d4f12307be6439606791a Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Fri, 24 Jan 2020 16:45:52 +0100 Subject: [PATCH] feat(MessageAttachment): add spoiler getter (#3713) --- src/structures/MessageAttachment.js | 11 +++++++++++ typings/index.d.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/structures/MessageAttachment.js b/src/structures/MessageAttachment.js index dd8b8a380..6db15c830 100644 --- a/src/structures/MessageAttachment.js +++ b/src/structures/MessageAttachment.js @@ -1,3 +1,5 @@ +const { basename } = require('path'); + /** * Represents an attachment in a message. */ @@ -63,6 +65,15 @@ class MessageAttachment { */ this.width = data.width; } + + /** + * Whether or not this attachment has been marked as a spoiler + * @type {boolean} + * @readonly + */ + get spoiler() { + return basename(this.url).startsWith('SPOILER_'); + } } module.exports = MessageAttachment; diff --git a/typings/index.d.ts b/typings/index.d.ts index b1f9c2b1c..d31af2c9f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -797,6 +797,7 @@ declare module 'discord.js' { public id: Snowflake; public message: Message; public proxyURL: string; + public readonly spoiler: boolean; public url: string; public width: number; }