From 676a895da7867c08c0499096fbbe21c5c02aea7a Mon Sep 17 00:00:00 2001 From: Programmix Date: Fri, 2 Dec 2016 19:35:01 -0800 Subject: [PATCH] Add Message - webhookID, isMemberMentioned (#946) * Add Message - webhookID, isMemberMentioned * Update Message.js * Update Message.js * Update Message.js * Update Message.js --- src/structures/Message.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index e015043da..0068ee60a 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -1,9 +1,10 @@ const Attachment = require('./MessageAttachment'); const Embed = require('./MessageEmbed'); +const MessageReaction = require('./MessageReaction'); +const GuildMember = require('./GuildMember'); const Collection = require('../util/Collection'); const Constants = require('../util/Constants'); const escapeMarkdown = require('../util/EscapeMarkdown'); -const MessageReaction = require('./MessageReaction'); /** * Represents a message on Discord @@ -163,6 +164,12 @@ class Message { this.reactions.set(id, new MessageReaction(this, reaction.emoji, reaction.count, reaction.me)); } } + + /* + * ID of the webhook that sent the message, if applicable + * @type {?string} + */ + this.webhookID = data.webhook_id || null; } patch(data) { // eslint-disable-line complexity @@ -343,6 +350,19 @@ class Message { return this.mentions.users.has(data) || this.mentions.channels.has(data) || this.mentions.roles.has(data); } + /** + * Whether or not a guild member is mentioned in this message. Takes into account + * user mentions, role mentions, and @everyone/@here mentions. + * @param {GuildMember|User} member Member/user to check for a mention of + * @returns {boolean} + */ + isMemberMentioned(member) { + if (this.mentions.everyone) return true; + if (this.mentions.users.has(member.id)) return true; + if (member instanceof GuildMember && member.roles.some(r => this.mentions.roles.has(r.id))) return true; + return false; + } + /** * Options that can be passed into editMessage * @typedef {Object} MessageEditOptions