Skip to content

Commit

Permalink
Add more options to MessageMentions#has (#2131)
Browse files Browse the repository at this point in the history
* Add more options to MessageMentions#has

* Rename ignoreSelf to ignoreDirect
  • Loading branch information
1Computer1 authored and iCrawl committed Nov 26, 2017
1 parent 950e65c commit 2f84d95
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/structures/MessageMentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,27 @@ class MessageMentions {
}

/**
* Check if a user is mentioned.
* Checks if a user, guild member, role, or channel 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
* @param {Object} [options] Options
* @param {boolean} [options.ignoreDirect=false] - Whether to ignore direct mentions to the item
* @param {boolean} [options.ignoreRoles=false] - Whether to ignore role mentions to a guild member
* @param {boolean} [options.ignoreEveryone=false] - Whether to ignore everyone/here mentions
* @returns {boolean}
*/
has(data, strict = true) {
if (strict && this.everyone) return true;
if (strict && data instanceof GuildMember) {
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreEveryone = false } = {}) {
if (!ignoreEveryone && this.everyone) return true;
if (!ignoreRoles && data instanceof GuildMember) {
for (const role of this.roles.values()) 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);

if (!ignoreDirect) {
const id = data.id || data;
return this.users.has(id) || this.channels.has(id) || this.roles.has(id);
}

return false;
}
}

Expand Down

0 comments on commit 2f84d95

Please sign in to comment.