From 963cf42e0dca888034e0b6e5fd99dbab698b0ccf Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Mon, 31 Jul 2017 21:49:00 -0500 Subject: [PATCH] add MessageMentions#has, remove old method (#1724) * Update MessageMentions.js * remove old method * smh * Update Message.js * Update MessageMentions.js * Update MessageMentions.js * Update MessageMentions.js --- src/structures/Message.js | 26 -------------------------- src/structures/MessageMentions.js | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 75ae5d7eb..52de85ddd 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -330,32 +330,6 @@ class Message { this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES); } - /** - * Whether or not a user, channel or role is mentioned in this message. - * @param {GuildChannel|User|Role|string} data Either a guild channel, user or a role object, or a string representing - * the ID of any of these - * @returns {boolean} - */ - isMentioned(data) { - data = data && data.id ? data.id : data; - 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 The member/user to check for a mention of - * @returns {boolean} - */ - isMemberMentioned(member) { - // Lazy-loading is used here to get around a circular dependency that breaks things - if (!GuildMember) GuildMember = require('./GuildMember'); - 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 diff --git a/src/structures/MessageMentions.js b/src/structures/MessageMentions.js index 0e8f6de83..85fc764cb 100644 --- a/src/structures/MessageMentions.js +++ b/src/structures/MessageMentions.js @@ -1,4 +1,5 @@ const Collection = require('../util/Collection'); +const GuildMember = require('./GuildMember'); /** * Keeps track of mentions in a {@link Message}. @@ -115,6 +116,22 @@ class MessageMentions { } return this._channels; } + + /** + * Check if a user is mentioned. Takes into account user mentions, role + * mentions, and @everyone/@here mentions. + * @param {UserResolvable|GuildMember|Role|GuildChannel} data User/GuildMember/Role/Channel to check + * @param {boolean} [strict=true] If role mentions and everyone/here mentions should be included + * @returns {boolean} + */ + has(data, strict = true) { + if (strict && this.everyone) return true; + if (strict && data instanceof GuildMember) { + for (const role of this.roles) if (data.roles.has(role.id)) return true; + } + const id = data.id || data; + return this.users.has(id) || this.channels.has(id) || this.roles.has(id); + } } /**